UIView with rounded corners and drop shadow?

前端 未结 30 2577
一整个雨季
一整个雨季 2020-11-22 08:00

I’ve been working on an application for a couple of years and received a simple design request: Round the corners on a UIView and add a drop shadow.To do as given below.

30条回答
  •  囚心锁ツ
    2020-11-22 08:27

    The following code snippet adds a border, border radius, and drop shadow to v, a UIView:

    // border radius
    [v.layer setCornerRadius:30.0f];
    
    // border
    [v.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [v.layer setBorderWidth:1.5f];
    
    // drop shadow
    [v.layer setShadowColor:[UIColor blackColor].CGColor];
    [v.layer setShadowOpacity:0.8];
    [v.layer setShadowRadius:3.0];
    [v.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
    

    You can adjust the settings to suit your needs.

    Also, add the QuartzCore framework to your project and:

    #import 
    

    See my other answer regarding masksToBounds.


    Note

    This may not work in all cases. If you find that this method interferes with other drawing operations that you are performing, please see this answer.

提交回复
热议问题