2016-09-12 12 views
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を印刷するときの結果です。

enter image description here

+1

Objective-Cのバージョンは次のとおりです。属性文字列のフォント属性を更新するには、http://stackoverflow.com/questions/19386849/looping-through-nsattributedstring-attributes-to-increase-font-sizeを参照してください。 – rmaddy

答えて

0

あなたは範囲を検索し、その範囲の属性を追加する必要があります。 「これはテストです」とします。このテキストでは、赤と太字の "This"とフォントサイズ40と青の色で "Test"を表示し、 "This"の範囲を探し、その範囲の属性(太字、赤色)を追加します。再び "Test"の範囲を見つけ、その範囲の属性(フォントサイズ、青色)を追加します。

関連する問題