Open auro-krishna opened 4 years ago
did you find a fix for this?
@mdeora Not yet
I fixed the issue by changing some code in Library
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
}
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
}
}
label.customTextAlignment = .center
textAlignment is not updating always aligns to left, How to fix this?