I was trying to add custom font to my today extension but UIFont
always return nil
.
Steps:
TodayViewController
of Today Widget but it always return nil
:- (void)viewDidLoad {
[super viewDidLoad];
UIFont* ft = [UIFont fontWithName:@"octicons-local" size:20];
}
I used the same method in my main project, and I can get the custom font. How can I fix it?
Maybe it's because you forgot to add key in your .plist
file.
Add the key Fonts provided by application
to a new row. Add items for each font you have added.
I met this problem also, and I DID targeting font to my target
and put fonts providing by application
in plist. But still gets nil when I tried to retrieve font.
Maybe because the font name you're using is wrong.
For Example (also the problem I met)
The Font which I dragged into my project name is trenolt.otf
But Use this name UIFont(name: "trenolt", size: 14)
gets nil
And According to Adding a Custom Font to Your App By Developer Documentation
I print out all the font familys and names
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
Then I get in console
["TruenoLt", "TruenoRg"]
And now use the printed name
UIFont(name: "TruenoLt", size: 14)
Gets
<UICTFont: 0x7fbc39a168b0> font-family: "Trueno"; font-weight: normal; font-style: normal; font-size: 14.00pt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With