gpt4 book ai didi

iphone - 如何将重复背景图像设置为表格单元格

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

当我使用以下代码将重复背景图像设置为 UITableView 时就可以了:

tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

但是当我使用它通过以下代码将重复背景图像设置为 UITableViewCell 时,没有任何反应,我不知道为什么,我也无法为此单元格设置背景颜色。

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

有人知道这样的方法吗?请帮助我!

最佳答案

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];

它将进入此代码块:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[RecipeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-on.png"]];
}
// Configure cell

return cell;
}

您还可以看到如何在其中设置选定的图像:selectedBackgroundView。

cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell-pressed.png"]];

我不确定是否要重复,但我很确定backgroundView可以设置contentMode。

关于iphone - 如何将重复背景图像设置为表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3234219/

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