我需要画一个划过的 UILabel。因此,我将 UILabel 子类化并实现如下:
@implementation UIStrikedLabel
- (void)drawTextInRect:(CGRect)rect{
[super drawTextInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextFillRect(context,CGRectMake(0,rect.size.height/2,rect.size.width,1));
}
@end
发生的情况是 UILabel 被划线,一行与整个标签一样长,但文本可以更短。有没有办法以像素为单位确定文本的长度,以便可以适当地绘制线条?
如果知道的话,我也愿意接受任何其他解决方案:)
最好的,埃里克