vik*_*tra 1 uitableview ios cagradientlayer
正如我在这里的问题中所讨论的,我尝试使用CAGradientLayer设置UITableView的背景颜色.我正在使用NSMutableArray中的一些值来填充UITableView,就像这样......
- (void)viewDidLoad
{
// ....
if (!navigationItems) {
navigationItems = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", nil];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:213.0f/255.0f green:91.0f/255.0f blue:92.0f/255.0f alpha:1.0f] CGColor][[UIColor colorWithRed:213.0f/255.0f green:0.0f blue:0.0f alpha:1.0f] CGColor], nil];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = colors;
gradientLayer.frame = tableView.bounds;
[tableView.layer insertSublayer:gradientLayer atIndex:0];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.textLabel.text = [navigationItems objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor blackColor];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
发生的情况是,使用初始值填充的单元格似乎与我设置的渐变颜色重叠.没有文字/边框出现在这些细胞(细胞值1,2,3,4在这种情况下).我在这里做错了什么?
将backgroundView设置为tableView对我有用.我是这样做的:
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = colors;
gradientLayer.frame = tableView.bounds;
//[tableView.layer insertSublayer:gradientLayer atIndex:0];
UIView *tableBackgroundView = [[UIView alloc] init];
[tableBackgroundView.layer insertSublayer:gradientLayer atIndex:0];
[self.tableView setBackgroundView:tableBackgroundView];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1129 次 |
| 最近记录: |