UIView with rounded corners and drop shadow?

前端 未结 30 2603
一整个雨季
一整个雨季 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:12

    One way to do this is to put the view with rounded corners in a view with the drop shadow.

    UIView* roundedView = [[UIView alloc] initWithFrame: frame];
    roundedView.layer.cornerRadius = 5.0;
    roundedView.layer.masksToBounds = YES;
    
    UIView* shadowView = [[UIView alloc] initWithFrame: frame];
    shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
    shadowView.layer.shadowRadius = 5.0;
    shadowView.layer.shadowOffset = CGSizeMake(3.0, 3.0);
    shadowView.layer.shadowOpacity = 1.0;
    [shadowView addSubview: roundedView];
    

    Then you can add the shadowView wherever you want.

提交回复
热议问题