Use iconfont in iOS and iconfont in ios

Source: Internet
Author: User

Use iconfont in iOS and iconfont in ios
How to use custom FontsBefore talking about the icon font, Let's first look at how common custom fonts are used in ios. The two principles are the same. The following uses KaushanScript-Regular as an example:Step 1: import a font fileDrag the font file into the project (the font formats supported by ios are :. ttf ,. otf, other formats are not clear): Then, in the project's resource pool, check whether the font file is added to the project. Open Build Phases of the xcode project to view:Step 2: configure the. plist FileRegister a new font in The. plist file. The. plist file often exists in the "Supporting Files" folder in the form of "[appname]-Info. plist. Add the new attribute "Fonts provided by application" to the. plist file. The value of this attribute is an array, which means you can register multiple Fonts here.Step 3: Find the font set nameAfter registration, we need to check whether the registration is successful and get the new font name. The check method is to print all installed fonts to see if the newly registered fonts are in it:

  1. For (NSString * family in [UIFont familyNames])
  2. {
  3. NSLog (@ "% @", family );
  4. For (NSString * name in [UIFont fontNamesForFamilyName: family])
  5. {
  6. NSLog (@ "% @", name );
  7. }
  8. }
After running, check whether any newly registered fonts exist in all the fonts printed in the console. If yes, the registration is successful and the font name ("Kaushan Script" Here) is used ") remember to use it later. Step 4: Use the new fontFinally, use the new font you added:
  1. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (10, 60,300, 50)];
  2. Label. font = [UIFont fontWithName: @ "Kaushan Script" size: 35];
  3. Label. text = @ "icon font ";
  4. Label. textColor = UIColorFromRGB (0xFF7300 );
  5. [Self. view addSubview: label];
Effect: Start using icon fontThe icon font is also a font, which is similar to the above mentioned, but there are some differences in the use. Here we take the fontello icon font library as an example. 1. Select the desired iconIn the fontello icon font library, select the desired icon and download the generated font file. 2. Follow the steps above to register the icon font to the project. 3. Find the unicode code corresponding to the iconUse the FontLab Studio 5 tool to open a font file (such as fontello. ttf), you can see the correspondence between the icon and the unicode code. 4. Use icons 
  1. UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (10, 60,300, 50)];
  2. Label. font = [UIFont fontWithName: @ "fontello" size: 35];
  3. Label. text = @ "\ u%e802 \ u%e801 \ u%e803 \ u%e804 \ u%e805 \ u%e81a ";
  4. Label. textColor = UIColorFromRGB (0xFF7300 );
  5. [Self. view addSubview: label];
In Objective-C, the custom unicode code must exist in the format of "\ ustme802. 5. Use the emoji emoticons LibraryHere, you can also use the icon of the apple emoji library. You don't need to add a new library here. You just need to find the correspondence between the emoji icon and unicode, but these icons are not vector images, zooming and zooming.
  1. UILabel * label5 = [[UILabel alloc] initWithFrame: CGRectMake (10,480,300, 50)];
  2. Label5.text = @ "\ u%e42a \ u%e525 \ u%e41c ";
  3. [Self. view addSubview: label5];
  6. Effect  7. Use the self-made icon fontIf the icon library described above does not meet your needs, or the required icons are distributed in multiple icon libraries and cannot be concentrated in one font file; you may need to create an icon font file by yourself. SummaryIn this way, in iOS development, you can not only directly go to the open-source icon library to find ready-made icons for use in the project, but also easily change the color and size of the icons, I believe it can free up the workload of many designers and engineers. Code onDemo Icon Font LibraryFontelloetao icon font library (Please note that the font name of the etao icon is "Untitled1". Are you negligent in generating the font ?) IcoMoonemoji emojis Library ReferencesCommon Mistakes With Adding Custom Fonts to Your iOS AppIcon font practices FontasticIconsios-fontawesomeCustom Unicode Characters in Objective-C

 

 

 

 

Original article:

Http://www.cocoachina.com/industry/20131111/7327.html

Https://github.com/JohnWong/IconFont

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.