// // StrikeThroughLabel.m // StrikeThroughLabelExample // // Created by Scott Hodgin on 12/14/10. // Copyright (c) 2010 __MyCompanyName__. All rights reserved. // #import "StrikeThroughLabel.h" @implementation StrikeThroughLabel @synthesize strikeThroughEnabled = _strikeThroughEnabled; - (void)drawTextInRect:(CGRect)rect{ [super drawTextInRect:rect]; CGSize textSize = NewStringSize(self.text, self.font); CGFloat strikeWidth = textSize.width; CGRect lineRect; if ([self textAlignment] == NSTextAlignmentRight) { lineRect = CGRectMake(rect.size.width - strikeWidth, rect.size.height/2, strikeWidth, 1); } else if ([self textAlignment] == NSTextAlignmentCenter) { lineRect = CGRectMake(rect.size.width/2 - strikeWidth/2, rect.size.height/2, strikeWidth, 1); } else { lineRect = CGRectMake(0, rect.size.height/2, strikeWidth, 1); } // if (_strikeThroughEnabled) { CGContextRef context = UIGraphicsGetCurrentContext(); // Get the fonts color. CGContextSetFillColorWithColor(context,self.textColor.CGColor); CGContextFillRect(context, lineRect); // } [super drawTextInRect:rect]; } - (void)setStrikeThroughEnabled:(BOOL)strikeThroughEnabled { _strikeThroughEnabled = strikeThroughEnabled; NSString *tempText = [self.text copy]; self.text = @""; self.text = tempText; [tempText release]; } @end