Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting RTL languages #62

Open
LogiStack opened this issue Aug 3, 2018 · 1 comment
Open

Supporting RTL languages #62

LogiStack opened this issue Aug 3, 2018 · 1 comment

Comments

@LogiStack
Copy link

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.

@Afrah-Tayyab
Copy link

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

  1. Open the "ExpandableLabel.swift" file.
  2. Initialise a variable in the class. i.e
    open var customTextAlignment: NSTextAlignment?
  3. 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
    }
  1. 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
        }
    }
  1. Clean the build folder
  2. Set the alignment of label in your class
    label.customTextAlignment = .center

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants