2

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?

  • string and arrtributed string created via inspector is not supported in IOS devices, if you need the Same OP you need to create as progrmatically : https://stackoverflow.com/questions/28496093/making-text-bold-using-attributed-string-in-swift – Anbu.Karthik Jan 23 '19 at 09:26
  • It seems to work fine for Xcode 10.1. Please share xcode version and code. – Khushal Dugar Jan 23 '19 at 09:54
  • As far as i think you are updating the value programatically. – Khushal Dugar Jan 23 '19 at 09:54
  • @KhushalDugar Xcode version is Version 10.1 (10B61). I have not created an outlet for that UILabel, so I don't think I am changing the value programatically. –  Jan 23 '19 at 10:13
  • Have you by any chance changed the `UILabel` text programatically using `myLabel.text = "Update Item"` ? – Marwen Doukh Jan 23 '19 at 11:22
  • @MarwenDoukh No, I have not created an outlet for that label –  Jan 23 '19 at 11:26
  • Can you try this with a built in system font? If that works it might indicate that something is wrong with the custom `PT Sans` font. – Rengers Jan 23 '19 at 11:28
  • @wvteijlingen You are right. If `Arial` font is used, this issue is resolved. –  Jan 23 '19 at 12:11
  • @iaaflaafc: I have added an answer regarding custom fonts. – Rengers Jan 23 '19 at 12:46

2 Answers2

2

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)

Rengers
  • 14,911
  • 1
  • 36
  • 54
-2

Please try

override func viewWillAppear(_ animated: Bool) {
        view.layoutIfNeeded()
}

this might be the issue.

Dixit Rathod
  • 177
  • 5