欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS 设置View阴影效果

程序员文章站 2023-12-17 19:21:46
需要设置 颜色 阴影半径 等元素 uiview *shadowview = [[uiview alloc] init]; shadowview.frame =...

需要设置 颜色 阴影半径 等元素

uiview *shadowview = [[uiview alloc] init];
 shadowview.frame = cgrectmake(100, 100, 100, 100);
 shadowview.center = self.view.center;
 shadowview.backgroundcolor = [uicolor whitecolor];
 //设置阴影颜色
 shadowview.layer.shadowcolor = [uicolor colorwithred:114.0/255.0 green:133.0/255.0 blue:152.0/255.0 alpha:1.0].cgcolor;
 //设置阴影的透明度
 shadowview.layer.shadowopacity = 0.1f;
 //设置阴影的偏移
 shadowview.layer.shadowoffset = cgsizemake(30.0f, 10.0f);
 //设置阴影半径
 shadowview.layer.shadowradius = 15.0f;
 //设置渲染内容被缓存
 shadowview.layer.shouldrasterize = yes;
 //超出父视图部分是否显示
 shadowview.layer.maskstobounds = no;
 shadowview.layer.borderwidth = 0.0;
 shadowview.layer.opaque = 0.10;
 shadowview.layer.cornerradius = 3.0;
 //栅格化处理
 shadowview.layer.rasterizationscale = [[uiscreen mainscreen]scale];
 //正常矩形
 uibezierpath *path = [uibezierpath bezierpathwithrect:shadowview.bounds];
 shadowview.layer.shadowpath = path.cgpath;
 [self.view addsubview:shadowview];

总结

以上所述是小编给大家介绍的ios 设置view阴影效果,希望对大家有所帮助

上一篇:

下一篇: