iOS Uilabel and Strikethrough

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.