使用CGContextShowTextAtPoint,如何做左右文本对齐? [英] Using CGContextShowTextAtPoint, how to do Left and Right text Justification?
本文介绍了使用CGContextShowTextAtPoint,如何做左右文本对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做UIView的子类化,如何使用CGContextShowTextAtPoint做左和右文本对齐?首先,你需要使用 [NSString sizeWithFont ...]来测量你的文本。
I am doing subclassing of UIView, how do I do Left and Right text justification using CGContextShowTextAtPoint? thx
推荐答案
] 方法。您将获得 size 使用
width
将文本放在正确的位置:
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:
伪代码:
if (justification == Left) {
//just use CGContextShowTextAtPoint
} else {
CGSize size = [text sizeWithFont:....];
CGContextShowTextAtPoint(context, self.bounds.width - size.width,....);
}
这篇关于使用CGContextShowTextAtPoint,如何做左右文本对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文