“少见"在可扩展标签 iOS 中 [英] "See Less" in ExpandableLabel iOS

查看:18
本文介绍了“少见"在可扩展标签 iOS 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方库 ExpandableLabel 来实现一个见更多功能.我正在寻找仅包含标签中而不是按钮中的文本的快速解决方案,因此这非常有效.在IB中添加库并更改标签类型后,我只需要几行代码:

I'm using the third party library ExpandableLabel to implement a see more feature. I am looking for swift only solutions that include the text in the label rather than in the button so this works perfectly. After adding the library and changing label type in IB I only need a few lines of code :

@IBOutlet weak var myLabel: ExpandableLabel!

myLabel = 3
myLabel = true  

然而,在完全扩展后,我无法弄清楚如何实现少见".我添加了委托方法:

I can't however figure out how to implement "see less" after it has been expanded fully. I added the delegate method :

ExpandableLabelDelegate 

和函数://MARK: ExpandableLabel 委托

and functions: // MARK: ExpandableLabel Delegate

func willExpandLabel(_ label: ExpandableLabel) {

}

func didExpandLabel(_ label: ExpandableLabel) {

}

func willCollapseLabel(_ label: ExpandableLabel) {

}

func didCollapseLabel(_ label: ExpandableLabel) {

}

func shouldCollapseLabel(_ label: ExpandableLabel) -> Bool {
    return true
}

试图控制这个过程,但仍然很挣扎.有没有其他人设法做到这一点?如果是这样,请你能帮我在这里...

to try and gain control of the process but have still struggled. Has anyone else managed to get this right? If so please can you help me out here...

推荐答案

根据我的个人经验,我注意到 expandedAttributedLink 仅在您将其设置在实际标签文本之前才有效.

Based on my personal experience, I noticed that the expandedAttributedLink works only if you set it before the actual label text.

infoLabel.setLessLinkWith(lessLink: "less", attributes: [NSFontAttributeName: boldItalicFont], position: nil)
infoLabel.text = viewModel.description
infoLabel.collapsedAttributedLink = NSAttributedString(string: "more", attributes: [NSFontAttributeName: boldItalicFont]);
infoLabel.ellipsis = NSAttributedString(string: "...")
infoLabel.collapsed = true

我能够通过查看 源文件.

I was able to identify this behaviour by looking at the setter of the text property inside the source file.

这篇关于“少见"在可扩展标签 iOS 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆