How to create shadow effect in uitableviewcell?

I am developing one application in which I want to create a shadow effect similar to the uitableviewcell shown below from bottom to bottom.

enter image description here

How can i do this? any tutorial or sample code? I checked http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html , http://www.touchthatfruit.com/?tag=uitableview and some others. But they have a shadow below uitableview with the same height. add a shadow to the side borders of each section containing the date (not the whole view of the table). I can create a drop-down shadow below. But what about the lateral borders of the last cell uitableview of each section. One way is to create an image and set it as the background of a tableviewcell. But how to resize the image, and it will look properly, because each section has a dynamic number of entries. One section has only 1 entry, and the other may contain 15 or more entries. (here the image is intended for the whole section containing the date) .i can have a separate image only for the last viewview table of each section. I know that. But is there any better approach or do it programmatically?

+5
source share
4 answers

This can be achieved using bezierpath: check the url for various shadow effects: http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths

-1
source

You can link to the following link for the shadow effect in uitableview, which will help you

try it

The fundamental point of view is the layer that is CALayer. You can access it through a layer property of the form:

myView.layer

CALayers , . , . , .

myView.layer.shadowOffset

myView.layer.shadowRadius

QuartzCore

0

? , UITableViewCell, ?

UIImageView UITableView, .

EDIT:

, , UIBezierPaths (http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UIBezierPath_class/Reference/Reference.html).

( ). drawRect. ( , , UITableViewCell).

UITableViewCell drawRect:.

, :

    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {

        /* Draw top image here */

        //now draw the background of the cell.
        UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 320, 50)];
        [[UIColor grayColor] set];
        [path1 fill];

        UIBezierPath *path2 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 52, 320, 50)];
        [[UIColor whiteColor] set];
        [path2 fill];

        UIBezierPath *path3 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 104, 320, 50)];
        [[UIColor grayColor] set];
        [path3 fill];

        UIBezierPath *path4 = [UIBezierPath bezierPathWithRect:CGRectMake(0, 156, 320, 50)];
        [[UIColor whiteColor] set];
        [path4 fill];

        //and so on...

        //Let draw the shadow behind the last portion of the cell.
        UIBezierPath *shadow = [UIBezierPath bezierPathWithRect:CGRectMake(0, 208, 320, 52)];
        [[UIColor darkGrayColor] set];
        [shadow fill];

        //Finally, here the last cell with a curved bottom
        UIBezierPath *path5 = [UIBezierPath bezierPath];
        [path5 moveToPoint:CGPointMake(0, 208)];
        [path5 addLineToPoint:CGPointMake(320, 208)];
        [path5 addLineToPoint:CGPointMake(320, 258)];
        [path5 addCurveToPoint:CGPointMake(0, 258) controlPoint1:CGPointMake(160, 254) controlPoint2:CGPointMake(160, 254)];
        [[UIColor grayColor] set];
        [path5 fill];
    }

, , , . , .

!

0

, ! !

0
source

All Articles