您的当前位置:首页正文

UIView 设置阴影无效的问题

来源:花图问答

设置方法:

//设置阴影
    _operationView.backgroundColor = [UIColor whiteColor];
    _operationView.layer.masksToBounds = NO;
    _operationView.layer.shadowColor = [[UIColor blackColor] CGColor];
    //    _operationView.layer.cornerRadius = 1; // if you like rounded corners
    _operationView.layer.shadowOffset = CGSizeMake(0, 5);
    _operationView.layer.shadowRadius = 5;
    _operationView.layer.shadowOpacity = 0.1;
   // _operationView.layer.shadowPath = [UIBezierPath bezierPathWithRect:_operationView.bounds].CGPath;//不要设置这个

如果无效,首先设置

_operationView.clipsToBounds = 0;
_operationView.layer.masksToBounds = NO;

然后是其父视图

self.containerView.clipsToBounds = 0;
self.containerView.layer.masksToBounds = 0;