I have a tableview where I customized the view cells and i want to draw the shadow on them. I have already use the view’s layer but if i draw the shadow by this way, my tableview is very very slow.
this is the code :
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.;
Thx you for help
Drawing shadows using these properties can have poor performance. You have a couple of options though:
You could set
shouldRasterizeon the layer to convert it to render the layer as a bitmap instead of redrawing (be careful: this is only useful if your view does not need to be redrawn often, and can end up being worse than the existing performance if used in the wrong scenario)The other option is to also use the
shadowPathproperty on the layer. According to theCALayerdocs:I would definitely use the
shadowPathproperty, and depending on the nature of the view, possibly set theshouldRasterizeflag as well