I need to draw a UILabel striked through. Therefore I subclassed UILabel and implemented it as follows:
@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
What happens is that the the UILabel is striked through with a line being as long as the whole label, but the text can be shorter.
Is there a way to determine the length of the text in pixels, such that the line can appropriately be drawn?
I'm also open to any other solutions, if known :)
Best,
Erik
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…