iosxcodefontsinterface-buildermongolian-vertical-script

Custom font displays in IB but not in simulator


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?

enter image description here

Notes:

Does anyone see my mistake or have any other ideas?

Update

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.

enter image description here

The problem can be reproduced as follows (using Xcode 7.1.1):

  1. Start a new single view project.
  2. Add the the font to the project (can be downloaded here from related github project)
  3. In Info.plist file add "Fonts provided by application" with font name "ChimeeWhiteMirrored.ttf".
  4. Confirm that the target's "Copy Bundle Resources" contains ChimeeWhiteMirrored.ttf.
  5. Add a UITextView to the storyboard.
  6. In the IB Attributes inspector paste in the following text: 1-10:           one two three four five six seven eight nine ten
  7. In the IB Attributes inspector set the font to Custom and the family to ChimeeWhiteMirrored.

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.


Solution

  • 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: