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
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...
Based on my personal experience, I noticed that the
expandedAttributedLink
works only if you set it before the actual label text.I was able to identify this behaviour by looking at the setter of the
text
property inside the source file.