Article Image
Article Image
read

I always thought that “Justified” would be an option for UILabel, unfortunately it used to be the case, but the option was removed with Xcode 6. The only option now is not use an AttributedString:

    var text = NSMutableAttributedString(data: NSLocalizedString("password-label-long-description", comment: "").dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSNumber(integer: Int(NSUTF8StringEncoding))], documentAttributes: nil, error: nil)

    let style = NSMutableParagraphStyle()
    style.alignment = NSTextAlignment.Justified
    text?.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSMakeRange(0, text!.length))

    mainLabel.attributedText = text
    mainLabel.textColor = UIColor.whiteColor()
Blog Logo

Valentino Urbano


Published

Image

Valentino Urbano

iOS Developer, Swift, Writer, Husband

Back to Overview