iOS/OS X - Justified Alignment on LAST LINE of text
core-text, ios, macos, objective-c
Solution
Thanks to omz's comment I stumbled across `CTLineCreateJustifiedLine`, which gives me just what I wanted. I'd still be interested if someone has a solution using a Cocoa Control (NSTextView), but i'd be surprised if there was anything tbh.
CTLineRef line = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attString);
line = CTLineCreateJustifiedLine(line, 1.0, dirtyRect.size.width);
CTLineDraw(line, context);
CFRelease(line);
Problem
I'm working on an app where I need all lines of text to be Justified alignment. The app will display 2 lines of text over the top of an image, creating an Advert like feeling to the picture. The problem is that both these lines of text need to be justified, but the 2nd line of text will never be justified. Or if I draw both lines separately then neither will be justified. If you specify `kCTJustifiedTextAlignment` in CoreText or `NSJustifiedTextAlignment` on `NSTextField/View` all but the last line of text are justified. The last line is aligned naturally. Is there a way to force the final line of a textfield or textview to be justified, so fill the width of the view? I've thought about using `CTLine` to draw each line separately, and specifying something on those to make all of them justified, but I'm not sure how to go about that either. Thanks