My collection view cell structure is described as below
For cellItemAtIndex
, I do the following
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"reusedCell" forIndexPath:indexPath];
// Set shadow around the cell
[cell.layer setMasksToBounds :NO ];
[cell.layer setShadowColor :[[UIColor whiteColor ] CGColor ] ];// shadow's color
[cell.layer setShadowOpacity :0.65 ]; // set the opacty
[cell.layer setShadowRadius :5.0 ]; // set the blur radius
[cell.layer setShadowOffset :CGSizeMake( 0 , 0 ) ]; // set shadow position
[cell.layer setShouldRasterize :YES ]; // tell the cell to render it’s CALayer as a bitmap
[cell.layer setShadowPath :[[UIBezierPath bezierPathWithRect:cell.bounds ] CGPath ] ]; // use a path to draw its shadow instead of using its
......................................................................
}
When I run the application on the device, the shadow is shown. However, my text for the labels are blurry. Please take a look at following imaged taken from my device
If I uncomment the bode block which is used to drop the shadow, the text are so clear as the following image
I am....totally lost. Does anybody have any ideas about this issue. Please help
You are rasterizing the layer, but the default rasterization scale is 1.0. It needs to be set to 2.0 for retina displays, otherwise the layer is presented only with half resolution.
cell.layer.rasterizationScale=[[UIScreen mainScreen] scale];
I would remove setShouldRasterize
, setShadowOffset
and setShadowPath
. It will work without them just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With