Some corners of the specified UIView for iOS development are rounded corners

Source: Internet
Author: User

Seems to be too busy for a long time, today has been more leisurely, just met a problem: Draw round corner. Not four fillets together, but one or a few rounded corners, then the Layer.cornerradius is not very useful.

For this scenario, several solutions are available on StackOverflow. One of the simplest and most elegant schemes is the use of Uibezierpath. A sample code is given below.

UIView*View2=[[UIViewAlloc]initWithFrame:CGRectMake(120,10,80,80)];View2.BackgroundColor=[Uicolor Redcolor];  [self.  View addsubview:view2];
Uibezierpath*Maskpath=[UibezierpathBezierpathwithroundedrect:View2.BoundsByroundingcorners:Uirectcornerbottomleft|UirectcornerbottomrightCornerradii:Cgsizemake(10,10)];Cashapelayer*Masklayer=[[CashapelayerAlloc]Init];Masklayer.Frame=View2.Bounds;Masklayer.Path=Maskpath.cgpath;view2.layer.mask = masklayer     
             

which

Byroundingcorners:uirectcornerbottomleft | Uirectcornerbottomright

Specifies the corners that need to be rounded corners. The parameter is of type Uirectcorner, and the optional values are:

* uirectcornertopleft* uirectcornertopright* uirectcornerbottomleft* uirectcornerbottomright* Uirectcornerallcorners

From the name it is easy to see the meaning of the representative, using the "|" To mix it up just fine.

Thanks to the original author's concise summary! I'll copy it.

Some corners of the specified UIView for iOS development are rounded corners

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.