IOS developed to get all font styles
Ios provides many font styles. Sometimes we may use different fonts when developing applications. Through this Demo, We can get all the font styles for us to choose.
First, get the font family name, and then get the font name through the family name.
_ FontArray = [[NSMutableArray alloc] initWithCapacity: 242]; for (NSString * familyName in [UIFont familyNames]) {NSLog (@ Font FamilyName =%@, familyName ); // * output font family name for (NSString * fontName in [UIFont fontNamesForFamilyName: familyName]) {NSLog (@ % @, fontName); [_ fontArray addObject: fontName];}
Then, use the following code to modify the font of the string.
NSString * testStr = @ It has 15 words; // NSString * testStr = @ I have a dozen of beautiful fifteen 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 ()]; [str addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange ()]; [str addAttribute: NSFontAttributeName value: [UIFont fontWithName: _ fontArray [indexPath. row] size: 30] range: NSMakeRange (0, 15)];
The effect of displaying Chinese and English is not very consistent. The effect of English is obvious, as shown in the following figure. This is available in the Demo.