2017-03-23 7 views
1

UITextViewで行間隔に関する考え方はありますか?私はそれを適用することはできません。以下は私のコードです。UITextViewで行間隔を適用できませんか?

import UIKit 

class DetailViewController: UIViewController { 
    @IBOutlet weak var itemTextView: UITextView! 
    var txtString: String? 
    var txtTitleBar:String? 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     //navigationController?.navigationItem.title = "Love" 
     self.title = txtTitleBar 

     //self.tabBarController?.navigationItem.title = "My Title" 
     itemTextView.text = txtString 
     itemTextView.font = UIFont(name: "Arial-Regular", size:20) 
     itemTextView.font = .systemFont(ofSize: 25) 
     (itemTextView.font?.lineHeight)! * 5 
    } 
} 

enter image description here

+0

(itemTextView.font .lineHeight?) 'は何:

let style = NSMutableParagraphStyle() style.lineSpacing = 20 let attributes = [NSParagraphStyleAttributeName : style] textView.attributedText = NSAttributedString(string: txtString, attributes: attributes) 

が、これはSO属性付き文字列の使用方法の詳細についてはお答えを参照してください。 ! * 5はやるべき? – rmaddy

+0

行間隔は適用されますが有効になりません –

+0

いいえ、行間隔は適用されません。行間の値を読み取り、その値に5を掛けます。しかし、結果は何もしません。 – rmaddy

答えて

0

Xcodeの9.2スウィフト4

let style = NSMutableParagraphStyle() 
style.lineSpacing = 0 
let attributes = [NSAttributedStringKey.paragraphStyle : style] 
txtViewAbout.attributedText = NSAttributedString(string: txtViewAbout.text, attributes: attributes) 
関連する問題