[英]Custom Font in IOS Not Reflected On Device
我遵循了這個教程 ,自定義字體顯示在我的故事板上但是當我執行我的應用程序(在模擬器或設備上)時,字體沒有反映出來。 有誰可以幫忙。 這就是我做的:
1- downloaded a .ttf file and copied it to my project
2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.
3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was shown on the storyboard correctly.
我錯過了什么嗎?
謝謝@Andrey Chernuka和@jcaron。 我通過將目標成員資格設置為我的項目然后退出項目(由於某種原因清理無效)並重新打開項目並設置了所有內容來解決問題。 當我打印print (UIFont.familyNames())
時出現字體名稱
您是否僅將.ttf文件夾添加到支持文件中。 然后像這樣編輯info.Plist
Application提供的字體作為數組
項目0為Heiti SC.ttf
現在你可以設置label.font = [UIFont fontWithName:@"Heiti SC" size:15];
然后,您還需要添加ttf文件以在目標構建階段復制捆綁資源。
您只需按照以下步驟操作。
第1步 - 下載.ttf文件並將其復制到我的項目第2步 - 在info.plist中添加了“由應用程序提供的字體”,並添加了一行,其名稱為我的自定義字體。
第3步 - 顯示添加的字體是否存在於項目中。 將過去復制到application:didFinishLaunchingWithOptions
NSLog(@"Available fonts: %@", [UIFont familyNames]);
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
{
NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]);
}
}
第4步 - 找到你的字體和同名的名字檢查故事板。
這絕對有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.