gpt4 book ai didi

ios - 设置 UITableViewCell backgroundView 和 selectedBackgroundView 在 iOS7 中不起作用

转载 作者:行者123 更新时间:2023-11-28 20:06:29 24 4
gpt4 key购买 nike

在以下任何方法中设置 backgroundView 和 selectedBackgroundView 似乎都不起作用。

UIView * bSg = [[UIView alloc] init];
UIView * bg = [[UIView alloc] init];
UIImageView *topSImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgActive"]];
UIImageView *topImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg"]];
[bg addSubview:topImage];
[bSg addSubview:topSImage];
self.backgroundView = bg;
self.selectedBackgroundView = bSg;

已尝试在所有这些单元格方法中进行设置

- (void)layoutSubviews
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
- (id)init

当放入 layoutSubviews 时,它在第一次加载时工作,但是当选择一个单元格时没有任何反应(也就是未设置 selectedBackgroundView)。

是的,我在 layoutSubviews 中设置了 self.backgroundColor = [UIColor clearColor] 以清除 iOS7 白色

最佳答案

这是我在表格 View 中为单元格设置背景图像的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
//set cell background
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shopsCellBackground"]];
background.backgroundColor = [UIColor clearColor];
background.opaque = NO;
cell.backgroundView = background;
...
}

我认为对您来说关键是在 tableView:cellForRowAtIndexPath TableView 方法中为单元格设置背景图像和选定的背景图像,而不是在您的单元格类中。

关于ios - 设置 UITableViewCell backgroundView 和 selectedBackgroundView 在 iOS7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21925718/

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