Reputation: 391
I am trying to make a UILabel
in Swift -- the label will display a simplified Chinese character. I am trying to use the Kaiti SC font that comes with the Mac, it is available in the Font Book and in all of the programs on the Mac, but when I list out the fonts using the following code, it does not show up.
let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNamesForFamilyName(familyName)
print("Font Names = [\(names)]")
}
The code for my UILabel is as follows:
let characterLabel:UILabel! = UILabel(frame: CGRectMake(600,140,300,300));
characterLabel.font = UIFont(name:"Kaiti SC" , size:250.0);
characterLabel.text = "说";
I would have thought all of the fonts on the Mac would be available in my Swift program. (The code, of course, does work with other fonts like "Baskerville", the Chinese characters simply don't look good in those fonts.) Any ideas?
Upvotes: 4
Views: 8251
Reputation: 321
And here Swift 5 Version:
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName)
print("Font Names = [\(names)]")
}
Upvotes: 7
Reputation: 391
This seems to be the answer to my question.
If you go to https://support.apple.com/en-ap/HT202771, you will see what fonts are available in iOS. In addition, it says "Apps can download the following fonts if necessary:" and these include a number of Asian and other fonts. They do not tell you how to access those fonts. Apparently, those fonts are on the Mac, and must be specifically downloaded to iOS.
This site shows you how to do that: http://www.perfectline.co/blog/2010/05/uiappfonts-custom-fonts-with-the-iphoneipad-3-2-sdk/
The two tricks I found necessary: (1) you need to add a new key in info.plist and (2) you must write a function to list out the font families, so you know the actual font name you need to use in your program. This site has such a function: http://giordanoscalzo.tumblr.com/post/95900320382/print-all-ios-fonts-in-swift
Upvotes: -1
Reputation: 69499
The font Kaiti SC
is not available on iOS, for a full list of available font check http://iosfonts.com/
Although the font is available on OS X does not mean that it is available or fully available on iOS.
Upvotes: 5