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