Rus*_*uss 0 uitableview uitextview uilabel ios swift
我试图在 tableView 单元格中为我的 UILabel 实现“显示更多/显示更少”功能。我试过在网上搜索解决方案,但它们似乎都过时了。
标题文本应该有 2 行,如果超过 2 行,它将扩展为全文
lazy var captionText: UILabel = {
let lbl = UILabel()
lbl.numberOfLines = 2
lbl.lineBreakMode = .byWordWrapping
return lbl
}()
func setupUI(viewModel: FeedModel) {
captionText.text = viewModel.postDescription
}
Run Code Online (Sandbox Code Playgroud)
我喜欢最终的结果是这样的:
你可以在 Swift 中尝试这个 3rd 方:https : //github.com/apploft/ExpandableLabel
将您的标签 UILabel 设置为 ExpandableLabel 并设置所需的属性:
yourLabel.numberOfLines = 2
yourLabel.collapsed = true
yourLabel.collapsedAttributedLink = NSAttributedString(string: "See more")
yourLabel.ellipsis = NSAttributedString(string: "...")
Run Code Online (Sandbox Code Playgroud)
它拥有ExpandableLabelDelegate的情况下,你要当链路已经触碰得到通知。
| 归档时间: |
|
| 查看次数: |
160 次 |
| 最近记录: |