You can use this extension below for Swift 5:
extension UILabel { func setJustifiedRight(_ title : String?) { if let desc = title { let text: NSMutableAttributedString = NSMutableAttributedString(string: desc) let paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle paragraphStyle.alignment = NSTextAlignment.justified paragraphStyle.lineBreakMode = NSLineBreakMode.byWordWrapping paragraphStyle.baseWritingDirection = NSWritingDirection.rightToLeft text.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, text.length)) self.attributedText = text } } }
and just set your text on your label like this
self.YourLabel.setJustifiedRight("your texts")
Saeed rahmatolahi
source share