在归因字符串

时间:2016-03-14 09:55:22

标签: html nsattributedstring

您好我有一个名为questionLabel的UILabel

let exStr = "SOME HTML STRING CONTAINING BOLD AND ITALIC WORDS"

var exAttrStr = try! NSMutableAttributedString(data: exStr.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
                    options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, namedNSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding],
                    documentAttributes: nil)

exAttrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor(colorLiteralRed: 51/255, green: 53/255, blue: 51/255, alpha: 1), range: NSRange(location:0,length:exAttrStr.length))

exAttrStr.addAttribute(NSFontAttributeName , value: SharedConstants.textFontSFUITextRegular(15), range: NSRange(location:0,length:exAttrStr.length))

questionLabel.attributedText = exAttrStr

我将字体设置为SFUIText常规。当我向exAttrStr添加属性时,属性文本的粗体和斜体部分将被覆盖。有没有办法可以使用SFUIText字体系列获得粗体和斜体字。

0 个答案:

没有答案