swift - Swift:ReadMoreTextView 库点击检测
问题描述
您好,我目前正在使用开源 ReadMoreTextView 库来扩展我的描述。如何仅在点击“阅读更多”或“...阅读少”时进行检测。目前在使用这些函数,hitTest 和 points 时,所有的 textView 都会被检测到。我的目标是,当我选择“阅读更多”时,我的 textView 和 tableView 标题将在其“阅读更少”时展开或折叠。这两个功能可以帮助但不知道什么是正确的方法。非常感谢!
let descriptionTextView: ReadMoreTextView = {
let textView = ReadMoreTextView()
let readMoreTextAttributes: [NSAttributedString.Key: Any] = [
NSAttributedString.Key.foregroundColor: UIColor.red,
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16)
]
let readLessTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.red,
NSAttributedString.Key.font: UIFont.italicSystemFont(ofSize: 16)
]
textView.attributedReadMoreText = NSAttributedString(string: "... Read more", attributes: readMoreTextAttributes)
textView.attributedReadLessText = NSAttributedString(string: " Read less", attributes: readLessTextAttributes)
textView.backgroundColor = .clear
textView.textColor = .white
textView.shouldTrim = true
textView.maximumNumberOfLines = 3
return textView
}()
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
}
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return true
}
解决方案
我也面临同样的问题。在与 ReadMoreTextView 库斗争之后,我使用了不同的库ExpandableLabel库,它解决了在更多按钮单击时获得回调的问题。希望这也能解决您的问题。
推荐阅读
- c# - 如何将文本框值绑定到 gridview 行的总数?
- python-3.x - tkinter 选项菜单不会设置标题
- python - 计算一组位置和特定点之间最小距离的最快方法(DataFrame)
- wordpress - Wordpress youtube 控制屏幕外
- bash - 如何从文件名中提取一个以下划线分隔的字段?
- c++ - 显示器之间的 Qt 自定义无框窗口中的绘画问题
- c# - Unity3D C# VR:在玩家的某个点产生对象
- set - Set 是什么意思
[] 集 = 新集 [] {setW, setX, setY, setZ}; 在 Java 中是什么意思? - arrays - 函数在数组中查找项目,快速
- javascript - 计数计时器使用javascript