Reputation: 749
I am doing subclassing of UIView, how do I do Left and Right text justification using CGContextShowTextAtPoint? thx
Upvotes: 2
Views: 705
Reputation: 950
First of all you need to measure your text using one of [NSString sizeWithFont...]
methods. You'll get size
Use it's width
to place your text in the right point:
pseudocode:
if (justification == Left) {
//just use CGContextShowTextAtPoint
} else {
CGSize size = [text sizeWithFont:....];
CGContextShowTextAtPoint(context, self.bounds.width - size.width,....);
}
Upvotes: 4