Woof
Woof

Reputation: 749

Using CGContextShowTextAtPoint, how to do Left and Right text Justification?

I am doing subclassing of UIView, how do I do Left and Right text justification using CGContextShowTextAtPoint? thx

Upvotes: 2

Views: 705

Answers (1)

Eldar Markov
Eldar Markov

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

Related Questions