Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make gradient background in UITableViewCell in iOS?

Tags:

iphone

ipad

I have followed the tutorial below to use CAGradientLayer to make gradient background in UITableViewCell.

http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html

Besides this tutorial, is there any other resources in this topic ?

Thanks.

like image 611
user403015 Avatar asked Aug 04 '11 15:08

user403015


People also ask

How do you create a gradient background in flutter?

To use gradients, you first need a Container widget, and within that you need to access its decoration property. Start by building the decoration of the Container widget in your _MyHomePageState build method in main.

How do you add color to a gradient?

Select the Gradient tool in the toolbar. In the selected artwork you'll see the gradient annotator, which shows the gradient slider and the color stops. Double-click a color stop on the artwork to edit the color, drag the color stops, click beneath the gradient slider to add new color stops, and more.


1 Answers

The always-awesome Ray Wenderlich did a tutorial on changing UITableViewCells and includes a gradient.

http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

If you want a quick and way, here's some code:

//include #import <QuartzCore/QuartzCore.h> in the header…

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

 if (cell == nil) {
        cell = [[DayCalendarCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = cell.bounds;
        gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor redColor]CGColor], nil];
        [cell.layer addSublayer:gradient];
    }        
    return cell;
}

You can change the colors but this will give you a good idea…

Good luck!

like image 183
SushiGrass Jacob Avatar answered Sep 28 '22 01:09

SushiGrass Jacob