Some corners of the specified UIView for iOS development (less than 4) are rounded corners

Source: Internet
Author: User

In iOS development, we often encounter the problem of view setting fillet, if we need to uiview 4 corners all rounded, it is quite simple, just set the Cornerradius property of its layer (the project needs to use the Quartzcore framework). This method is not good when you want to specify a few corners (less than 4) to be rounded and the other constant.


For the latter case, the following is a relatively simple and elegant scheme, that is, the use of Uibezierpath.

The sample code is as follows:

UIView *testview = [[UIView Alloc] initWithFrame:CGRectMake (100,10,80,];testview).backgroundcolor = [uicolor redcolor];[ self.view Addsubview:testview]; uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect: Testview.bounds byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright cornerradii:cgsizemake (10, 10)]; cashapelayer *masklayer = [[cashapelayer Alloc] Init];masklayer.frame = Testview.bounds;masklayer.path = maskpath< span class= "variable". Cgpath;testview.layer.mask = Masklayer;      

Among them, 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.

Some corners of the specified UIView for iOS development (less than 4) 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.