1.I copy ttf file to my project like this
if let customFont = UIFont(name: "myFont", size: 54) {
testLabel.font = customFont
} else {
print("Font loading failed!")
}
it print Font loading failed!
why?
then i try to print all fonts like this:
for fontFamily in UIFont.familyNames {
print(UIFont.fontNames(forFamilyName: fontFamily))
}
But I couldn’t find my custom font
I don’t know why, I am very grateful for the help
2
Answers
I suspect you might not have added it to the target you are building, or the font name in the
.plist
file might be different.Here, you can find Apple’s tutorial to verify your steps and ensure everything is set up correctly.
You can also check it from the storyboard. Select the custom fonts and see if your font is showing in the storyboard or not. I just tried the same thing, and it works with the same steps.
Also, check the target membership of the font as well.
Here is my code: