Ich bin Attribut auf Etikett setzen mein Code ist unten geschrieben, das einzige Problem ist meine Schrift und Farbe wird nicht auf Etikett gerendert.Zugeschnittene Zeichenfolge funktioniert nicht auf Etikett
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)")
}
}
}
kann jemand helfen?
Das ist normal. Sehen Sie sich das Dokument 'NSAttributedString (data: options: documentsAttributes:)' an. 'NSFontAttributeName' und' NSForegroundColorAttributeName' werden ignoriert. Bei ihnen danach zum 'attributedString' (kann dann einen' NSMutableAttributedString' verwenden, um seine Attribute modifizieren zu können.). – Larme
http://stackoverflow.com/questions/27728466/use-multiple-font-colors-in-a-single-label-swift/27728516#27728516 –