IOS開發得到所有的字型樣式

來源:互聯網
上載者:User

IOS開發得到所有的字型樣式

ios的提供了很多的字型樣式。有時候我們在開發應用的時候可能用到不同的字型,通過此Demo我們可以擷取到所有的字型樣式供我們選擇。
首先擷取字型字型族科名字,再通過族科的名字擷取到字型的名字。

    _fontArray = [[NSMutableArray alloc] initWithCapacity:242];    for (NSString * familyName in [UIFont familyNames]) {        NSLog(@Font FamilyName = %@,familyName); //*輸出字型族科名字        for (NSString * fontName in [UIFont fontNamesForFamilyName:familyName]) {         NSLog(@%@,fontName);            [_fontArray addObject:fontName];        }
然後再使用如下代碼就可以修改字串的字型。
 NSString * testStr = @It has 15 words;//    NSString * testStr  = @我隨手一打就是漂亮的十五個字了;    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:testStr];    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,3)];    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3,4)];    [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(7,4)];    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:_fontArray[indexPath.row] size:30] range:NSMakeRange(0, 15)];
顯示中文和英文的效果不是很一致,英文的效果明顯一些,如下是部分效果。具體在Demo裡面有。

 



 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.