iOS developed to get all font styles

Source: Internet
Author: User

iOS offers a lot of font styles. Sometimes we may use different fonts when we develop the application, so we can get all the font styles to choose from this demo.
First get the font family name, and then get the name of the font by the name of the family branch.

    _fontarray = [[Nsmutablearray alloc] initwithcapacity:242];    For (NSString * familyname in [Uifont Familynames]) {        NSLog (@ "Font familyname =%@", familyname),//* output font family section name for        ( NSString * FontName in [Uifont Fontnamesforfamilyname:familyname]) {         NSLog (@ "\t%@", fontname);            [_fontarray addobject:fontname];        }
You can then modify the font of the string using the following code.
NSString * teststr = @ "It has words";//    NSString * teststr  = @ "I have a dozen is beautiful 15 words";    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)];
Display the Chinese and English effect is not very consistent, the English effect is obvious, the following is part of the effect. Specific in the demo inside there.




demo:http://download.csdn.net/detail/u011496891/8663909
Reprint Please specify source: http://blog.csdn.net/zhouzhoujianquan/article/details/45503357

iOS developed to get all font styles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.