关于如何设置阴影的同时裁剪图片
2018-01-14 21:51
260 查看
具体实现的套路有两种
1、在图层下方在添加一个背景图层, 分别设置。
2、通过layer的shadowPath设置
如果是一个矩形或者是圆,用
1、在图层下方在添加一个背景图层, 分别设置。
self.layerView1.layer.cornerRadius = 20.0f; self.layerView2.layer.cornerRadius = 20.0f; //add a border to our layers self.layerView1.layer.borderWidth = 5.0f; self.layerView2.layer.borderWidth = 5.0f; //add a shadow to layerView1 self.layerView1.layer.shadowOpacity = 0.5f; self.layerView1.layer.shadowOffset = CGSizeMake(0.0f, 5.0f); self.layerView1.layer.shadowRadius = 5.0f; //add same shadow to shadowView (not layerView2) self.shadowView.layer.shadowOpacity = 0.5f; self.shadowView.layer.shadowOffset = CGSizeMake(0.0f, 5.0f); self.shadowView.layer.shadowRadius = 5.0f; //enable clipping on the second layer self.layerView2.layer.masksToBounds = YES;
2、通过layer的shadowPath设置
@interface ViewController () @property (nonatomic, weak) IBOutlet UIView *layerView1; @property (nonatomic, weak) IBOutlet UIView *layerView2; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //enable layer shadows self.layerView1.layer.shadowOpacity = 0.5f; self.layerView2.layer.shadowOpacity = 0.5f; //create a square shadow CGMutablePathRef squarePath = CGPathCreateMutable(); CGPathAddRect(squarePath, NULL, self.layerView1.bounds); self.layerView1.layer.shadowPath = squarePath; CGPathRelease(squarePath); //create a circular shadow CGMutablePathRef circlePath = CGPathCreateMutable(); CGPathAddEllipseInRect(circlePath, NULL, self.layerView2.bounds); self.layerView2.layer.shadowPath = circlePath; CGPathRelease(circlePath); } @end
如果是一个矩形或者是圆,用
CGPath会相当简单明了。但是如果是更加复杂一点的图形,
UIBezierPath
这个类会更加合适。
相关文章推荐
- 如何给一个View同时设置圆角和阴影
- 关于如何设置echart图例(legend)的位置
- 关于hook设置函数如何支持多核CPU的一个说明
- 如何设置常驻通知的同时通知栏不显示小图标&如何在兼容低版本的前提下调用高版本的api
- 设置了“在桌面上为图标标签使用阴影“却没有效果,如何解决。
- 关于hook设置函数如何支持多核CPU的一个说明
- 窗口设置为Qt::Popup时, 如何去掉窗口阴影?
- 关于Dev—c++ 4.9.9.2 如何设置调试
- 关于Excel操作编写的一个软件设计构思案例[连载] --如何创建快捷菜单执行人机交互操作、软件初始化设置
- 关于域中如何设置"我的文档"定向也称漫游
- 关于电脑DNS出错,如何修复和手动设置DNS
- 关于STM32 PB3 PB4 如何设置成普通GPIO的配置
- 双网卡电脑如何设置同时上两个不同的网络
- 关于CCS中如何设置printf函数的问题
- 双网卡如何设置才能同时访问内网和外网
- 关于pjax 如何设置不缓存加载页面里面的js文件和不修改浏览器中的URL地址
- MVC架构下,关于如何设置DropDownList的默认选中项以及修改后填充以后的设置选中项
- 关于如何打开谷歌的电脑设置方法
- 关于如何设置收藏本站和设为首页
- 关于如何去掉submit按钮背景阴影的解决方法