IOS UIView Setting rounded corners

Source: Internet
Author: User

UIView setting rounded corners

1, relatively simple situation, uiview Four Corners are rounded corner:

    UIView *aview = [[UIView alloc] init];        Aview.frame = CGRectMake (0, 0, +);    Aview.backgroundcolor = [Uicolor redcolor];        Set rounded border        AView.layer.cornerRadius = 8;        AView.layer.masksToBounds = YES;        Set border and border color        aView.layer.borderWidth = 8;        AView.layer.borderColor =[[Uicolor Graycolor] cgcolor];        [Self.view Addsubview:aview];

2. Set one or a few of the four corners as rounded corners

    UIView *aview = [[UIView alloc] init];        Aview.frame = CGRectMake (0, 0, +);    Aview.backgroundcolor = [Uicolor redcolor];        [Self.view Addsubview:aview];        Set the desired fillet position and size    uibezierpath *maskpath = [Uibezierpath bezierPathWithRoundedRect:aView.bounds byroundingcorners : Uirectcornerbottomleft | Uirectcornerbottomright Cornerradii:cgsizemake (Ten)];    Cashapelayer *masklayer = [[Cashapelayer alloc] init];    Masklayer.frame = aview.bounds;    Masklayer.path = Maskpath.cgpath;    AView.layer.mask = Masklayer;

Among them, Uirectcornerbottomleft,uirectcornerbottomright is the angle that can be selected.

typedef ns_options (Nsuinteger, Uirectcorner) {    Uirectcornertopleft     = 1 << 0,    Uirectcornertopright    = 1 << 1,    uirectcornerbottomleft  = 1 << 2,    Uirectcornerbottomright = 1 << 3,    uirectcornerallcorners  = ~0ul};

The above enumeration is a corner that you can choose from: Top left, top right, bottom left, bottom right, and so on.

IOS UIView Setting 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.