I need to draw a UILabel. So 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 UILabel is shaded with a line that has the length of the entire label, but the text may be shorter. Is there a way to determine the length of the text in pixels so that the line can be drawn accordingly?
I am also open to any other solutions, if known :)
Best, Erik
objective-c iphone uilabel
Erik Aug 27 '09 at 12:10 2009-08-27 12:10
source share