UIView with rounded corners and drop shadow?

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

    I make some changes to the code of daniel.gindi

    This is all you need to make it work.

    + (void)putView:(UIView*)view insideShadowWithColor:(UIColor*)color andBlur:         (CGFloat)blur andOffset:(CGSize)shadowOffset andOpacity:(CGFloat)shadowOpacity
    {
        CGRect shadowFrame = view.frame;
        UIView * shadow = [[UIView alloc] initWithFrame:shadowFrame];
        shadow.backgroundColor = [UIColor redColor];
        shadow.userInteractionEnabled = YES; // Modify this if needed
        shadow.layer.shadowColor = color.CGColor;
        shadow.layer.shadowOffset = shadowOffset;
        shadow.layer.shadowRadius = blur;
        shadow.layer.cornerRadius = view.layer.cornerRadius;
        shadow.layer.masksToBounds = NO;
        shadow.clipsToBounds = NO;
        shadow.layer.shadowOpacity = shadowOpacity;
        [view.superview insertSubview:shadow belowSubview:view];
    }
    

提交回复
热议问题