In the process of development, sometimes the fonts provided by Xcode do not meet our needs, so we need to add additional third-party fonts.
Provide a font download address: Find the font.
The first page is the SWIFT code using third-party fonts, and the second page is OC using third-party fonts.
Integration process 1. download. TTF fonts
First download the. TTF font and drag the font into the project.
2. Increase fonts provided by application in Info.plist
or add the following code to the Info.plist source:
<key>UIAppFonts</key> <array> <string>Amano.ttf</string> <string>Amelia BT.ttf</string> <string>Wzk.ttf</string> </array>
3. Use in Swift code
let testLabel = UILabel.init(frame: CGRectMake(10012012050))testLabel.font = UIFont.init"woziku-bsdsm-CN4262"20)testLabel.text"湖工电气"testLabel.textAlignment = NSTextAlignment.CentertestLabel.backgroundColor = UIColor.orangeColor()self.view.addSubview(testLabel)
4. Use in OC Code
self.showLabel.font = [UIFont fontWithName:@"woziku-bsdsm-CN4262" size:18];self.showLabel.text = @"湖工电气";
5. Use in IB
6. View the fonts inside Xcode
// 打印字体letUIFont.familyNames()print(fonts)
In the print results, we can see the three fonts we added: Amano,amelia BT and woziku-bsdsm-cn4262.
["Copperplate","Heiti SC","Iowan old Style","Kohinoor Telugu","Courier New","Heiti TC","Gill Sans","Apple SD Gothic Neo","woziku-bsdsm-cn4262","Marker Felt","Thonburi","Avenir Next Condensed","Tamil Sangam MN","Helvetica Neue","Gurmukhi MN","Times New Roman","Georgia","Apple Color Emoji","Arial rounded MT Bold","Kailasa","Kohinoor Devanagari","Kohinoor Bangla","Chalkboard SE","Sinhala Sangam MN","Pingfang TC","Gujarati Sangam MN","Damascus","Noteworthy","Geeza Pro","Avenir","Academy engraved Let","Mishafi","Futura","Farah","Kannada Sangam MN","Arial Hebrew","Arial"," party Let","Chalkduster","Hoefler Text","Optima","Palatino","Lao Sangam MN","Malayalam Sangam MN","Al Nile","Bradley Hand","Pingfang HK","Trebuchet MS","Helvetica","Courier","Cochin","Amano","Amelia BT","Devanagari Sangam MN","Oriya Sangam MN","Hiragino Mincho ProN","Snell Roundhand","Zapf Dingbats","Bodoni","Verdana","American Typewriter","Avenir Next","Baskerville","Khmer Sangam MN","Didot","Savoye let","Bodoni Ornaments","Symbol","Menlo","Bodoni smallcaps","Papyrus","Hiragino Sans","Pingfang SC","Euphemia UCAS","Telugu Sangam MN","Bangla Sangam MN","Zapfino","Bodoni Oldstyle"]
Summarize
Integration and use of third-party fonts, without the above difficulties, follow the appropriate steps to do so. One thing to note: The name of the font file is not necessarily the name of the font library. We need to print the font library in Xcode to see the name of our font library. The above project file structure inside the font library to view the file name and the code inside the fonts used: woziku-bsdsm-cn4262 is a good explanation.
Code: Swift-font.
IOS Add TTF Font