Using Iconfont in IOS

Source: Internet
Author: User

How to use a custom fontBefore you speak the icon font, first look at how normal custom fonts are used in iOS, and the two principles are the same. Here take Kaushanscript-regular as an example:Step 1: Import font FilesDrag a font file into the project (iOS supported font formats are:. TTF,. OTF, other formats indeterminate): Then in the project's resource pool, confirm that the font files are joined to the project, open the Xcode project in build phases to view:Step 2: Configure the. plist fileRegistering the newly added font in the. plist file, the. plist file often exists in the supporting files folder in the form of "[appname]-info.plist". Add a new property in the. plist file "Fonts provided by Application", the value of this property is an array, which means that you can register multiple fonts here.Step 3: Find the font set nameAfter registering, we need to detect whether the registration is successful and obtain a new font name, the detection method is to print out all the installed fonts, to see if the newly registered fonts are inside:
    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, see if there are any newly registered fonts in all the font sets printed in the console, if so, the registration is successful, and the font name (here is "Kaushan Script"), remember to leave it behind.Step 4: Use new fontsFinally, you'll be using the latest fonts you've 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 font of the icon is also the font, using the same way as above, just a few differences in the application; Take Fontello's icon font library for example.1. Select the desired iconIn the Fontello icon Font Library, select the icon you want and download the generated font file.2. Follow the steps above to register the icon font in the project3. Find the Unicode code corresponding to the iconUsing 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 the icon
    1. UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (10, 60, 300, 50)];
    2. Label.font = [Uifont fontwithname:@"Fontello" size:35];
    3. Label.text = @"\u0000e802 \u0000e801 \u0000e803 \u0000e804 \u0000e805 \u0000e81a";
    4. Label.textcolor = Uicolorfromrgb (0xff7300);
    5. [Self.view Addsubview:label];
In Objective-c, the custom Unicode code needs to exist in a format such as "\u0000e802".5. Use Emoji Emoticons libraryYou can also use the Apple Emoji Expression Library icon, here do not need a new font library, as long as the emoji icon and Unicode to find the corresponding relationship between the good, but these icons are not vectors, scaling please self-esteem.
    1. UILabel *label5 = [[UILabel alloc] Initwithframe:cgrectmake (10, 480, 300, 50)];
    2. Label5.text = @"\u0000e42a\u0000e525\u0000e41c";
    3. [Self.view Addsubview:label5];
6. Effects7. Use the homemade icon fontIf the icon library described above does not meet your needs, or if the desired icon is distributed across multiple icon libraries and cannot be centralized into a single font file, then you may need to make an icon font file yourself.SummaryIn this way, in iOS development, not only can go directly to open-source icon library to find ready-made icons used in the project, but also can easily change the color of the icon, size, I believe that can liberate a lot of designers and engineers work.on the CodeDemoIcon Font LibraryFontelloetao Icon Font Library (here is a question to note that the Etao icon font named "Untitled1", is not the generation of the font of the classmate negligence? ) Icomoonemoji Emoticons LibraryReferencesCommon mistakes with Adding Custom Fonts to Your iOS AppIcon font practice Fontasticiconsios-fontawesomecustom Unicode characters In Objective-c

Original link:

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

Https://github.com/JohnWong/IconFont

Using Iconfont in IOS

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.