Change the Uiimageview to rounded corners and circles

Source: Internet
Author: User

1. Draw rounded Corners

    CornerView.layer.cornerRadius =;    CornerView.layer.masksToBounds = YES;



Maskstobounds prevents child elements from spilling over the parent view.

If a square is to be set to a circle, the code is:

    CornerView.layer.cornerRadius = CORNERVIEW.FRAME.SIZE.HEIGHT/2;    CornerView.layer.masksToBounds = YES;

2. Draw the Border

    BorderView.layer.borderWidth = 1.0;    BorderView.layer.borderColor = [Uicolor blackcolor]. Cgcolor;


Note that Cgcolor is used instead of uicolor.

3. Draw Shadows

    ShadowView.layer.shadowColor = [Uicolor Redcolor]. Cgcolor;    ShadowView.layer.shadowOffset = Cgsizemake (5.0, 5.0);    shadowView.layer.shadowOpacity = YES;


Offset is the shift offset, which is the direction in which the increment of the frame x, y coordinates is being expressed.

The opacity is transparent, and the default is 0, which means transparency. So we're going to set the opacity to 1 or yes, which means it's opaque, or it can be set to 0.5 or a similar value to be translucent.

Change the Uiimageview to rounded corners and circles

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.