iOS为UIView设置阴影效果
程序员文章站
2023-12-19 20:11:16
uiview的阴影设置主要通过uiview的layer的相关属性来设置
阴影的颜色
imgview.layer.shadowcolor = [uicolor...
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;
总结
以上就是这篇文章的全部内容,希望能对各位ios开发者们能有所帮助,如果有疑问大家可以留言交流。