0
JSONから受け取ったテキストから属性付き文字列を作成しています。私はそのテキストをテキストビューに入れます。アトリビュートテキストのフォントサイズの変更と書式設定の変更
let descriptionVC = BenefitDescriptionViewController()
let attributedString = try! NSAttributedString(data: descriptionString.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
descriptionVC.labelString = attributedString
descriptionVC
override func viewDidLoad() {
super.viewDidLoad()
// print("Attributed String: \(labelString)")
if let descriptionString = labelString {
descriptionTextView.attributedText = descriptionString
descriptionTextView.textColor = UIColor.white
descriptionTextView.font = UIFont.systemFont(ofSize: 17.0)
}
}
私は、このような大胆されているテキストの一部として、書式設定を維持しますが、フォントを大きくしたいです。フォントサイズを増やそうとすると、他の書式設定はすべて消えてしまいます。
これはlabelStringを印刷するときの結果です。
Objective-Cのバージョンは次のとおりです。属性文字列のフォント属性を更新するには、http://stackoverflow.com/questions/19386849/looping-through-nsattributedstring-attributes-to-increase-font-sizeを参照してください。 – rmaddy