Create custom subclass Deletelinelabel, inherit from Uilabel, and then in custom subclass Deletelinelabel
Method One (context):
1- (void) DrawRect: (cgrect) rect {2 [Super Drawrect:rect];3 4Cgcontextrefref=Uigraphicsgetcurrentcontext ();5 6 //draw a starting point7Cgcontextmovetopoint (ref,0, Rect.size.height *0.5);8 //Draw end Point9Cgcontextaddlinetopoint (ref, Rect.size.width, Rect.size.height *0.5);Ten //Finish Drawing OneCgcontextstrokepath (ref); A - -}
Method two (Draw rectangle):
1- (void) DrawRect: (cgrect) rect {2 //Call Super's DrawRect: method to draw the label's text according to the parent class3 [Super Drawrect:rect];4 5 //take the color of the text as the color of the strikethrough (same text color, can not write)6[Self.textcolorSet];7 8 //Draw (Find the middle position of the label)9Uirectfill (CGRectMake (0, Rect.size.height *0.5, Rect.size.width,1));Ten One}
Finish the effect:
iOS Uilabel and Strikethrough