2017-09-06 30 views
0

textviewに行間を追加したいと思います。次のコードでは、 "textViewにはmember attributedTextがありません"というエラーが表示されます。 この問題を解決するにはどうすればよいですか?textviewに行間を追加しないでください

import UIKit 

@objc protocol TextViewCellProtocol:NSObjectProtocol { 
    func textViewCellDidTouchedButton(_ cell:TextViewCell) 
} 

class TextViewCell: UICollectionViewCell { 

    @IBOutlet var textView:FuriganaTextView! 

    let style = NSMutableParagraphStyle() 
    style.lineSpacing = 40 
    let attributes = [NSParagraphStyleAttributeName : style] 
    textView.attributedText = NSAttributedString(string: textView.text, 
                  attributes: attributes) 
} 

答えて

1

私はあなたが使用しているのTextViewクラス(FuriganaTextView)がメンバーattributedTextを持っていないので、あなたがエラーを取得していると信じています。彼らのgitHub documentationを確認した後。私はあなたがTextKitないUITextViewのサブクラスの上に構築されてFuriganaTextView

textView.contents = NSAttributedString(string: textView.text, 
                 attributes: attributes) 

よう
+0

こんにちは正直なところですが、別のエラーが発生しています。 FuriganatextView「タイプの値が 『テキスト』何のメンバーを持っていない 『』。」 – risa8

+0

risa8 @私がチェックし、あなたに –

+0

を更新しますが、あなたにたくさんありがとうございました:) – risa8

0

FuriganaTextViewcontents性質に起因する文字列を指定することにより、FuriganaTextViewに起因するテキストを追加することができると思います。 furiganaTextView.contentsプロパティを使用して帰属文字列を設定することができます。ここにはusage exampleがあります。

// Prepare furigana contents 
// Note: The order of the furiganas provided to the FuriganaTextView is important. 
// It must be ascending in manner of the location of the range, 
// otherwise the furiganas may not be rendered at the correct position. 
let furiganas = [ 
    Furigana(text: "た", original: "田", range: NSMakeRange(0, 1)), 
    Furigana(text: "なか", original: "中", range: NSMakeRange(1, 1)), 
] 
let contents = NSAttributedString(string: "田中さん、中華料理を食べたことありますか。") 

// Tell FuriganaTextView about 
// the furiganas (which is an array of the Furigana struct) 
// and the contents to display (a NSAttributedString) 
furiganaTextView.furiganas = furiganas 
furiganaTextView.contents = contents 

// To customize the text view, use the contentView 
// contentView will return a valid UITextView after 
// the contents has been set 
furiganaTextView.contentView?.backgroundColor = UIColor.lightGray 
関連する問題