Align Text: A follow up of resolved problem with new question


(Andreas Kiel) #1

(Lost in "HTML to Attributed String to HTML" conversion)
Shane mentioned in his latest answer/code that it can be used for other attributes.
I tried to modify the code to change the text alignment of a “multi paragraph and style text block” (NSAttributedString) that way but didn’t have any success.
Obviously I still have big knowledge gaps on how objc works.

Maybe somebody can help again.


(Shane Stanley) #2

You probably need to enumerate the NSParagraphStyles, get them via the NSParagraphStyleAttributeName attribute.


(Andreas Kiel) #3

Thanks Shane,

I think I got all the parts I need, but I don’t succeed to assemble them in a correct way.

if (aValue’s isKindOfClass:(current application’s NSParagraphStyle)) then
set aAlign to (((aValue’s valueForKeyPath:“alignment”) as integer) + 1)
set aAlignVal to (item aAlign of {“Left”, “Right”, “Center”, “Justified”, “Natural”})
log aAlignVal
end if

So I can read the value but haven’t found a way to change it.


(Shane Stanley) #4

Make a NSMutableParagraphStyle using mutableCopy(), change it to suit, then set the new value. NSMutableParagraphStyle is a class, and alignment is a property.