Create your own font and display it in the project
This tutorial is complex but has practical value. It can be used to extract the font downloaded from the internet and create your own font for display in the project. Sometimes the experience of loading custom texts is very large, and the 8-9 m Chinese font usually occupies a large proportion, and we only need a few Chinese characters in it. This blog post does this.
First, create a font
1. Download Tool
2. Download the font
3. Import the font to the tool and find the Chinese character based on the Chinese Character
4. Create your own font
5. Search for the three characters of travel xianming, copy and paste them, and assign values to the code points and names.
6. Export to TTF font
In this way, a Custom font is created.
The following section shows the font display.
Source code:
//// Rootviewcontroller. M // font // created by youxianming on 14-9-6. // copyright (c) 2014 youxianming. all rights reserved. // # import "rootviewcontroller. H "# import" fontpool. H "@ interface rootviewcontroller () @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; self. view. backgroundcolor = [uicolor blackcolor]; [fontpool registerfont: bundlefont (@ "youxianming. TTF ") withname: @" youxianming "]; uilabel * label = [[uilabel alloc] initwithframe: cgrectmake (0, 0,320, 22)]; label. center = self. view. center; label. font = [uifont fontwithname: custom_font (@ "youxianming", 0) Size: 18]; label. textcolor = [uicolor cyancolor]; label. textalignment = nstextalignmentcenter; label. TEXT = @ "youxianming siege Lion"; [self. view addsubview: Label];} @ end
The final result is as follows:
Because my font only contains the encoding of the three Chinese characters youxianming and does not include the Chinese characters of the siege lions, it turns into a black body when the siege lions are displayed. Here, it indicates that the attack was successful :)
Create your own font and display it in the project