然后重写drawTextInRect:方法
代码如下:
-(void)drawTextInRect:(CGRect)rect
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);
}
}
CGContextRef context=UIGraphicsGetCurrentContext();
if(self.strikelineColor!=nil)
{
CGFloat r,g,b,a;
[self.strikelineColor getRed:&r green:&g blue:&b alpha:&a];
CGContextSetRGBFillColor(context,r,g,b,a);
}
CGContextFillRect(context,lineRect);
}
}