Bre*_*den 5 iphone uitableview uicolor
我试图给出tableviewcell与众不同backgroundColor的东西,colorwithPatternImage并且它没有按预期工作.文档中没有说明一次只能使用一种模式.
假设我有3行,我设置背景如下:
Cell1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]];
Cell2.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]];
Cell3.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]];
Run Code Online (Sandbox Code Playgroud)
所有3行都是红色的.就好像有一些全局颜色被返回.
colorWithPatternImagekCGColorSpaceModelPattern 1无论传入什么图像,每次调用都会返回.如果一次只有1个全局模式,那么颜色应该是最后一个,换句话说就是蓝色.
这毫无意义.有没有人对Apple在这里做什么有任何内部专业知识?
编辑 我甚至在完全独立的视图中使用不同的模式,它仍然影响其他视图的模式.我确信,虽然文档没有说明这一点,但你一次只能使用一个UIColor图像模式.伤心.
什么是Cell1?在哪里(以什么方法)设置这些?
我会说你应该做这一切
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// create cell
}
// Set up the cell...
// set up a background color
if (something)
cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"red.png"]];
else (another)
cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"green.png"]];
else
cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"blue.png"]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22858 次 |
| 最近记录: |