Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applying shadow for the view makes my text blurry

My collection view cell structure is described as below

enter image description here

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

enter image description here

If I uncomment the bode block which is used to drop the shadow, the text are so clear as the following image enter image description here

I am....totally lost. Does anybody have any ideas about this issue. Please help

like image 765
tranvutuan Avatar asked Nov 09 '12 03:11

tranvutuan


2 Answers

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];
like image 121
jarnoh Avatar answered Sep 22 '22 10:09

jarnoh


I would remove setShouldRasterize, setShadowOffset and setShadowPath. It will work without them just fine.

like image 22
Davyd Geyl Avatar answered Sep 20 '22 10:09

Davyd Geyl