[英]How i can draw the shadow for my uiview
我有一个tableview,在其中我自定义了视图单元格,我想在它们上绘制阴影。 我已经使用过视图的图层,但是如果以此方式绘制阴影,则tableview会非常慢。 这是代码:
UIView *foreground = [[UIView alloc] initWithFrame:CGRectMake(8., 8., 305, 290.)];
foreground.tag = kForegroundTag;
foreground.backgroundColor = [UIColor whiteColor];
/* Draw from here */
foreground.layer.shadowColor = [UIColor blackColor].CGColor;
foreground.layer.shadowOpacity = 0.7;
foreground.layer.shadowOffset = CGSizeMake(0., 1.);
foreground.layer.shadowRadius = 3.;
谢谢你的帮助
使用这些属性绘制阴影的性能可能很差。 不过,您有两种选择:
您可以在shouldRasterize
上设置shouldRasterize
,以将其转换为位图而不是重新绘制(请小心:这仅在不需要经常重新绘制视图的情况下才有用,并且如果不重新绘制则可能会比现有性能差)在错误的情况下使用)
另一个选择是也使用shadowPath
上的shadowPath
属性。 根据CALayer
文档:
指定显式路径通常可以提高渲染性能
我肯定会使用shadowPath
属性,并根据视图的性质,可能还设置了shouldRasterize
标志
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.