如何添加“阅读更多”在Swift的Uilabel的第三行结束时
我需要在标签第三行的末尾添加更多。
这样我需要:
/添加读取的uilabel“> add” ...在uilabel的末尾读取更多“ ...因此,我需要像下面的尝试一样尝试
。在此处,如果说明更多,则我需要在第三行的结尾显示剩下的文本..
如果超过3行,我可以扩展标签
override func viewDidLoad() {
super.viewDidLoad()
despLbl.text = publicProGenInfo?.result?.user?.description
despLbl.numberOfLines = 3//despLbl.maxNumberOfLines//3
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gesture:)))
despLbl.addGestureRecognizer(tap)
despLbl.isUserInteractionEnabled = true
tap.delegate = self
}
@objc func labelAction(gesture: UITapGestureRecognizer)
{
if despLbl.numberOfLines == 3 {
despLbl.numberOfLines = despLbl.maxNumberOfLines
} else {
despLbl.numberOfLines = 3
}
}
代码:使用此代码, :得到这样的..在第三行之后,如何添加阅读更多
文本...请执行指南
I need to add read more
at the end of the 3rd line in label.
like this i need:
Note: i have tried this answer Add "...Read More" to the end of UILabel but here read more action is not working and expand collapse also not working.. so tried like below
Actually i need to show description in label.. here if the description if more then 3 lines then i need to show read more
at end of the 3rd line and need to expand the label with remaining text..
code: with this code i can expand the label if more than 3 lines but i need to show read more
at end of the third line
override func viewDidLoad() {
super.viewDidLoad()
despLbl.text = publicProGenInfo?.result?.user?.description
despLbl.numberOfLines = 3//despLbl.maxNumberOfLines//3
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.labelAction(gesture:)))
despLbl.addGestureRecognizer(tap)
despLbl.isUserInteractionEnabled = true
tap.delegate = self
}
@objc func labelAction(gesture: UITapGestureRecognizer)
{
if despLbl.numberOfLines == 3 {
despLbl.numberOfLines = despLbl.maxNumberOfLines
} else {
despLbl.numberOfLines = 3
}
}
o/p: getting like this.. here after 3rd line how to add read more
text... please do guide
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
readmoretextview 是一个很好的选择,有几行代码,您可以实现此行为。
ReadMoreTextView is a good option for this purpose, with a few lines of code you can achieve this behavior.