

仔细观察两幅图,我们发现,图1只有向右向下方向有阴影,图2四周都有阴影。项目要求实现四周有阴影。之前想着让UI给个背景切图算了。查阅资料发现,其实要实现四周添加阴影,竟如此简单。直接看代码。
self.contentView.layer.cornerRadius = 4.0f;
self.contentView.layer.masksToBounds = YES;
self.layer.shadowColor = [UIColor grayColor].CGColor;
// self.layer.shadowOffset = CGSizeMake(3, 3);//有偏移量的情况,默认向右向下有阴影
self.layer.shadowOffset = CGSizeZero; //设置偏移量为0,四周都有阴影
self.layer.shadowRadius = 3.0f;//阴影半径,默认3
self.layer.shadowOpacity = 0.3f;//阴影透明度,默认0
self.layer.masksToBounds = NO;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.layer.cornerRadius].CGPath;*
网友评论