ios - 将行间距添加到 textView 不起作用

标签 ios swift

我想给 textView 添加行间距。使用以下代码,我收到错误消息“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)
}

最佳答案

我相信您收到错误是因为您正在使用的 textView 类 (FuriganaTextView) 没有成员 attributedText。检查他们的gitHub documentation后.我想您可以通过将属性字符串指定到 FuriganaTextViewcontents 属性来将属性文本添加到 FuriganaTextView,例如

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

关于ios - 将行间距添加到 textView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46067907/

相关文章:

ios - 如何使用 UITextview 增加 View 大小?

ios - 使用 Swift + SpriteKit 将节点移动到手指

Swift 将命令传递到 jar 文件中

objective-c - 在 iPhone 5 上,UITableView 以 3.5 英寸格式截断

objective-c - ARC - 取消分配图片库选择器?

ios - 如何停止将超链接移动到新行 UITextView

swift - 预加载纹理图集完成处理程序不起作用

ios - Facebook 无法在 app swift 3 中打开页面

ios - Firebase 从异步调用返回 bool 值

swift - 如何将 AdMob GADBannerView 添加到每个 View