UIView的阴影设置主要通过UIView的
layer
的相关属性来设置
- 阴影的颜色
imgView.layer.shadowColor = [UIColor blackColor].CGColor;
- 阴影的透明度
imgView.layer.shadowOpacity = 0.8f;
- 阴影的圆角
imgView.layer.shadowRadius = 4.f;
- 阴影偏移量
imgView.layer.shadowOffset = CGSizeMake(4,4);
imgView.layer.shadowOffset = CGSizeMake(0,0);
其实从偏移量上可以看出来,即使偏移量为(0,0)时,围绕view的四周依然能看到一定阴影。
- 阴影的路径
除了通过上面的操作,我们还可以设定阴影的路径//路径阴影 UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(-5, -5)]; //添加直线 [path addLineToPoint:CGPointMake(paintingWidth /2, -15)]; [path addLineToPoint:CGPointMake(paintingWidth +5, -5)]; [path addLineToPoint:CGPointMake(paintingWidth +15, paintingHeight /2)]; [path addLineToPoint:CGPointMake(paintingWidth +5, paintingHeight +5)]; [path addLineToPoint:CGPointMake(paintingWidth /2, paintingHeight +15)]; [path addLineToPoint:CGPointMake(-5, paintingHeight +5)]; [path addLineToPoint:CGPointMake(-15, paintingHeight /2)]; [path addLineToPoint:CGPointMake(-5, -5)]; //设置阴影路径 imgView.layer.shadowPath = path.CGPath;
有关UIBezierPath的知识请看: UIBezierPath介绍
作者:MajorLMJ
链接:http://www.jianshu.com/p/575ce7d7b68f
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
iOS开发之UI控件阴影效果
最新推荐文章于 2021-01-14 17:38:05 发布