我有一个表格 View ,每个单元格都有自定义图像背景。在正常模式下,背景是完美的并且填满了所有单元格。当 tableView 进入编辑模式时,“-”按钮出现在左侧,所有对象都缩进,在左侧我的背景有问题:有一个白色区域。谁能帮我?背景图像足够大,可以填满所有单元格,但在编辑模式下会移动。我能解决吗?非常感谢!
更新:
我在我的 UITableViewCell 子类中使用了这段代码:
- (void) layoutSubviews
{
UIImage *backgroundImage = [UIImage imageNamed:@"sfondoCella2.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.bounds];
bgView.image = backgroundImage;
self.backgroundView = bgView;
[bgView release];
}
要设置背景和 appranetly 在正常模式下运行良好,但当您进入编辑模式时,一切都出错了:圆圈红色删除按钮不出现,单元格的缩进(与 IB 中设置的背景完美)不正确。
最佳答案
我认为没有办法通过 IB 添加背景图像。相反,我假设您只是添加一个 UIImage subview 。
我已经在代码中为表格单元格添加了背景图片,但我没有遇到您描述的问题。
UIImage *backgroundImage = [UIImage imageNamed:@"my-bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.backgroundView.frame];
bgView.image = backgroundImage;
cell.backgroundView = bgView;
[bgView release];
理想情况下,您可以在自定义中执行此操作 UITableViewCell的 layoutSubviews 方法,然后告诉 IB 这是您的单元格的类。
通过扩展 UITableViewCell,您可以重写以下方法并准确控制单元格在编辑模式或选中时的外观。
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
关于ios - 如何在编辑模式下调整 UITableViewCell 背景的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2421718/