Search code examples
iosuilabelnsattributedstring

Difference in how a UILabel is shown in the interface builder and in the simulator


I have created a .xib file and have added a UILabel with attributed text. The contents of the label consists of 2 words - one is in regular font while the other word is bold. The interface builder shows the label correctly as follows

interface builder

However, when the app is run on the simulator, the following is shown- simulator

Can anyone point out why this is happening?


Solution

  • Seeing as it works with a system font such as Arial, it is probably a problem with the custom font not being recognised. Try the following:

    1. Did you add the custom fonts files to your Xcode project, and to the build target?

    2. Did you add them to the Info.plist using the UIAppFonts key? This key should contain an array of the names of the font files you added to your project (e.g. Custom-Font.ttf)