I have a method that sets NSAttributedString :
func setBold(text: String) -> NSMutableAttributedString {
guard let font = UIFont.CustomNormalBoldItalic() else {
fatalError("font not found")
}
let string = NSMutableAttributedString(string:"\(text)", attributes: [NSFontAttributeName : font])
self.setAttributedString(string)
return self
}
And here is what it is called, which works fine:
let formattedString = NSMutableAttributedString()
formattedString.setBold("Your text here")
However, I am trying to set the substring text to NSLocalizedString so that it is bold. So I would try like this:
let formattedString = NSMutableAttributedString()
return NSAttributedString(string: String.localizedStringWithFormat(
NSLocalizedString("message", comment: ""),
formattedString.setBold(NSLocalizedString("message.day", comment: "")),
NSLocalizedString("message.time", comment: "")
))
Instead of " Today, starting at 10 pm", he gives the following result:
Today{
NSFont = "<UICTFont: 0x7fb75d4f1330> font-family: \"CustomText-MediumItalic\"; font-weight: normal; font-style: italic; font-size: 14.00pt";
} starting at 10pm {
}
Can someone tell me where I'm wrong, or how can I fix this? The reason I have another method is because I have many localized strings to set the bold and thought it might be a simple solution. Open to other ideas / solutions that do not contain many repetitions / lines of code.