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.
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.
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.
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!
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