Open LogiStack opened 6 years ago
I fixed the issue by changing some code in Library. Notes : when ever you update your pods you must have to change this code again this might be the drawback
Open the "ExpandableLabel.swift" file.
Initialise a variable in the class. i.e
open var customTextAlignment: NSTextAlignment?
Replace copyWithParagraphAttribute function with following function
func copyWithParagraphAttribute(_ font: UIFont,_ alignment: NSTextAlignment) -> NSAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 1.05
paragraphStyle.alignment = alignment
paragraphStyle.lineSpacing = 0.0
paragraphStyle.minimumLineHeight = font.lineHeight
paragraphStyle.maximumLineHeight = font.lineHeight
let copy = NSMutableAttributedString(attributedString: self)
let range = NSRange(location: 0, length: copy.length)
copy.addAttribute(.paragraphStyle, value: paragraphStyle, range: range)
copy.addAttribute(.baselineOffset, value: font.pointSize * 0.08, range: range)
return copy
}
Replace the attributedText variable with following code
open override var attributedText: NSAttributedString? {
set(attributedText) {
if let attributedText = attributedText?.copyWithAddedFontAttribute(font).copyWithParagraphAttribute(font, self. customTextAlignment ?? .left),
attributedText.length > 0 {
self.collapsedText = getCollapsedText(for: attributedText, link: (linkHighlighted) ? collapsedAttributedLink.copyWithHighlightedColor() : self.collapsedAttributedLink)
self.expandedText = getExpandedText(for: attributedText, link: (linkHighlighted) ? expandedAttributedLink?.copyWithHighlightedColor() : self.expandedAttributedLink)
super.attributedText = (self.collapsed) ? self.collapsedText : self.expandedText
} else {
self.expandedText = nil
self.collapsedText = nil
super.attributedText = nil
}
}
get {
return super.attributedText
}
}
Clean the build folder
Set the alignment of label in your class
label.customTextAlignment = .center
The expandableLabel's textAlignment is always .left without referring textAlignment property.
I've set it to .Right or .Natural, but the label shows the text always as .Left
Please help me solve this issue.