如何在iOS中的UITableViewCell中制作渐变背景? [英] How to make gradient background in UITableViewCell in iOS?
问题描述
我按照下面的教程使用CAGradientLayer在UITableViewCell中制作渐变背景。
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 ?
谢谢。
推荐答案
总是很棒的Ray Wenderlich做了一个关于更改UITableViewCells的教程并包含了一个渐变。
The always-awesome Ray Wenderlich did a tutorial on changing UITableViewCells and includes a gradient.
http://www.raywenderlich.com/2033/core-graphics-101-lines-矩形和渐变
如果你想快速方式,这里有一些代码:
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…
祝你好运!
这篇关于如何在iOS中的UITableViewCell中制作渐变背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!