UILabel에 중앙선(취소선) 표시하기. (UIStrikeLabel)
UILabel 에 set 된 Text의 Size 알기.
CGSize textSize = [[UILabel text] sizeWithFont:[UILabel font]];
drawTextInRect:
Draws the receiver’s text (or its shadow) in the specified rectangle.
#define strikeHeight 1.0
@implementation UIStrikeLabel
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGSize textSize = [[self text] sizeWithFont:[self font]];
CGFloat strikeWidth = textSize.width;
CGContextFillRect(context, CGRectMake(0, rect.size.height/2, strikeWidth, strikeHeight));
}
@end
if([self strike]) {
CGSize textSize = [[self text] sizeWithFont:[self font]];
CGFloat strikeWidth = textSize.width;
CGContextFillRect(context, [self getStrikeRect:strikeWidth]);
}
switch ([self textAlignment]) {
default:
case UITextAlignmentLeft:
x = 0;
break;
case UITextAlignmentCenter:
x = (self.frame.size.width - strikeWidth) / 2.0;
break;
case UITextAlignmentRight:
x = self.frame.size.width - strikeWidth;
break;
}