IOS developed to get all font styles

Source: Internet
Author: User

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.

 



 

Related Article

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.