gpt4 book ai didi

iphone - UIColor colorWithPatternImage 仅使用一张图像

转载 作者:行者123 更新时间:2023-12-03 18:57:03 28 4
gpt4 key购买 nike

我试图为 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"]];

所有 3 行都是红色的。就好像有一些全局颜色被返回。

无论传入什么图像,

colorWithPatternImage 每次调用都会返回 kCGColorSpaceModelPattern 1。如果您一次只有 1 个全局模式,则颜色应该是最后一组,换句话说是蓝色。

这没有任何意义。有谁对苹果在这里所做的事情有任何内部专业知识吗?

编辑我什至在完全独立的 View 中使用不同的模式,它仍然会影响其他 View 的模式。尽管文档没有说明这一点,但我确信您一次只能使用一种 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"]];
}

关于iphone - UIColor colorWithPatternImage 仅使用一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1406579/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com