I have set up a UITextView
and a UILabel
to use a custom font. (It is a vertically mirrored Mongolian font, but I also included English text so that you can see the effect.) The words display in the Interface Builder, but in the simulator most of the characters in the UITextView
are just empty boxes. Strangely, in the characters in the UILabel
do display correctly in the simulator.
How do I get them to display in the UITextView
as well?
UITextView
and the UILabel
.Info.plist
and added my custom font to it.
This question is a very similar one (but is different because it doesn't mention the UITextView
and UILabel
issue). At the time of this writing the OP for that question has not indicated if the top voted answer helped or not. I ran the code in that answer to confirm that my font is really in the bundle. I got the following result, which confirms that it is in the bundle, so that still doesn't solve my problem.
Family : ChimeeWhiteMirrored
Font : ChimeeWhiteMirrored
Does anyone see my mistake or have any other ideas?
After receiving @darkheartfelt's downvote and comment to my answer below, I recreated my original problem thinking maybe I had missed something. Although in iOS 9 the font displays somewhat differently in the simulator, the basic problem is still there: it looks ok in IB but not in the simulator.
The problem can be reproduced as follows (using Xcode 7.1.1):
UITextView
to the storyboard.1-10: one two three four five six seven eight nine ten
This reproduces the problem for the special characters and as I described in my answer below, the only thing I have found to solve this problem it to set the font in code.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// set custom font
textView.font = UIFont(name: "ChimeeWhiteMirrored", size: (textView.font?.pointSize)!)
}
}
If I'm wrong or missing something then please let me know. Until then I'll have to continue using my accepted answer below.
It appears that, while when I first imported the font into my project I selected "Add to target membership", after inspecting the font, it was not added to the target! It worked just fine in Interface Builder, but didn't work in the sim or when compiled.
Selecting the font file in the project folder view and checking the target membership box fixed it:
If you are using webfont then download.ttf file and drop it into your project . Don't forget to Check mark on copy items if needed on xcode
Next add this on info plist
<key>UIAppFonts</key>
<array>
<string>Your fontname.ttf</string>
<string>Bakersfield Bold.ttf</string>
</array>
Now take a look the font family name. Which you will find on font file also. From where you have downloaded you will get there also. Like i added font which ttf file name is : Bakersfield Bold.ttf for this fontname is : Bakersfield-Bold Thats it. Like
UIFont *helvFont = [UIFont fontWithName:@"Bakersfield-Bold" size:14.0];
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