INDLinkLabel icon indicating copy to clipboard operation
INDLinkLabel copied to clipboard

text alignment

Open mkchoi212 opened this issue 9 years ago • 7 comments

Tried using .textalignment but didn't work and I couldn't see any attributes with NSTextContainer that dealt with text alignment.

Is this possible?

mkchoi212 avatar Jul 15 '15 15:07 mkchoi212

Looks like a bug, good catch! In the mean time, you can create an NSMutableParagraphStyle and set the alignment property, and then set that object in the attributes dictionary of your NSAttributedString using the NSParagraphStyleAttributeName key.

indragiek avatar Jul 16 '15 05:07 indragiek

@indragiek Cool, thanks for the suggestion!

mkchoi212 avatar Jul 16 '15 13:07 mkchoi212

 var txtstyle = NSMutableParagraphStyle()
        txtstyle.alignment = NSTextAlignment.Center

        let RTFPath = NSBundle.mainBundle().pathForResource("text", ofType: "rtf")!
        let RTFData = NSData(contentsOfFile: RTFPath)!
        let options = [NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType, NSParagraphStyleAttributeName : txtstyle]

        policyLabel.numberOfLines = 0
        policyLabel.attributedText = NSAttributedString(data: RTFData, options: options, documentAttributes: nil, error: nil)
        policyLabel.delegate = self

Just tried this and it didn't work!

mkchoi212 avatar Jul 16 '15 14:07 mkchoi212

NSParagraphStyleAttributeName is a key that can't be passed in the options parameter as you have there. In this case, you will need to create an NSMutableAttributedString and apply the attribute like this:

let attrString = NSMutableAttributedString(data: RTFData, options: options, documentAttributes: nil, error: nil)
attrString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSMakeRange(0, attrString.length))
policyLabel.attributedText = attrString;

indragiek avatar Jul 17 '15 04:07 indragiek

@indragiek Thanks! Got it to work

mkchoi212 avatar Jul 17 '15 23:07 mkchoi212

This ticket shouldn't be closed. Is still an issue :)

raulriera avatar Jun 15 '17 13:06 raulriera

@raulriera Good point!

mkchoi212 avatar Jun 15 '17 13:06 mkchoi212