我怎样才能为我的uiview画出阴影

时间:2012-08-29 22:04:01

标签: ios uiview drawing shadow

我有一个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.;

求你帮忙

1 个答案:

答案 0 :(得分:0)

使用这些属性绘制阴影可能会导致性能下降。你有两个选择:

您可以在图层上设置shouldRasterize以将其转换为将图层渲染为位图而不是重绘(请注意:这仅在您的视图不需要经常重绘时才有用,并且可能会结束如果在错误的场景中使用,则比现有的性能更差)

另一种选择是在图层上使用shadowPath属性。根据{{​​1}}文档:

  

指定显式路径通常可以提高渲染性能

我肯定会使用CALayer属性,并且根据视图的性质,可能还设置shadowPath标志