Uicolor colorwithpatternimage는 하나의 이미지 만 사용합니다
-
05-07-2019 - |
문제
나는 주려고 노력하고있다 tableviewcell
다른 backgroundColor
S와 함께 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
한 번에 하나의 글로벌 패턴 만 있다는 것이 사실이라면 각 호출에 대해 각 호출에 대해 색상이 마지막 세트, 즉 파란색으로되어야합니다.
이것은 말이되지 않습니다. Apple이 여기서하는 일에 대한 내부 전문 지식이 있습니까?
편집하다나는 완전히 별도의보기에서 다른 패턴을 사용하며 여전히 다른보기의 패턴에 영향을 미칩니다. 문서가 이것을 언급하지는 않지만 한 번에 하나의 uicolor 이미지 패턴으로 제한되어 있다고 확신합니다. 슬퍼.
해결책
As far I can see this is not or no longer true. I have here a couple of UITableViewCells, where each has a different backgroundImage, without any problems.
다른 팁
What is Cell1? Where (in what method) are you setting these?
I would say that you should be doing all this in
- (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"]];
}