UITextViewに行間を設定したいです。
カスタムクラスを作り、そこでUITextViewを生成する処理を行って、メインでそれを表示させます。
やりかた自体はわかります。
必要なものは、
NSLayoutManagerDelegateを呼び出す
設定したいtextViewにlayoutManagerを。
textView.layoutManager.delegate = self
これを追加
lang
1func layoutManager(layoutManager: NSLayoutManager, lineSpacingAfterGlyphAtIndex glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat { 2 return 10 //行間 3}
が、カスタムクラスにした場合に
textView.layoutManager.delegate = このターゲットと
func layoutmanagerというのをどこにセットしたらいいかわかりません。
宜しくお願いします。
ViewController.swift
lang
1let PG = CustomTextView.paragraph(frame, text: paragraph) 2self.view.addSubview(PG)
CustomTextView.swift
lang
1import UIKit 2 3class CustomTextView: UIView , NSLayoutManagerDelegate { 4 class func article(customFrame: CGRect , text:String) -> UITextView { 5 6 // TextView生成する. 7 var myTextView: UITextView = UITextView(frame: customFrame) 8 9 //いろいろ設定 10 11 //これで、行間を調節する うまく動かない 12 myTextView.layoutManager.delegate = CustomTextView() 13 14 return myTextView 15 } 16 17 func layoutManager(layoutManager: NSLayoutManager, lineSpacingAfterGlyphAtIndex glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat { 18 return 10 //行間 19 } 20}
あなたの回答
tips
プレビュー