Я устанавливаю атрибут на этикетке, код которой написан ниже, Единственная проблема заключается в том, что мой шрифт и цвет не отображаются на этикетке.Связанная строка, не работающая с меткой
func setDataWithContent(content: EmbeddedContent) {
if let htmlString = content.text {
do {
let encodedData = htmlString.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding,
NSFontAttributeName: UIFont(name: "SourceSansPro-Regular", size:16)!,
NSForegroundColorAttributeName: UIColor.redColor()
]
let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
htmlTextLabel.attributedText = attributedString
} catch {
fatalError("Error: \(error)")
}
}
}
Может ли кто-нибудь помочь?
Это нормально. Посмотрите на документ 'NSAttributedString (data: options: documentsAttributes:)'. 'NSFontAttributeName' и' NSForegroundColorAttributeName' будут проигнорированы. На них потом на 'attributedString' (можно использовать' NSMutableAttributedString', чтобы иметь возможность изменять его атрибуты.). – Larme
http://stackoverflow.com/questions/27728466/use-multiple-font-colors-in-a-single-label-swift/27728516#27728516 –