How to right-justify UILabel text?
thanks
You should set text alignment to justified and set attributed string base writing direction to RightToLeft:
var label: UILabel = ...
var text: NSMutableAttributedString = ...
var paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.alignment = NSTextAlignment.Justified
paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping
paragraphStyle.baseWritingDirection = NSWritingDirection.RightToLeft
text.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, text.length))
label.attributedText = text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With