ios - 如何在编辑模式下调整 UITableViewCell 背景的大小

标签 ios iphone objective-c uitableview

我有一个表格 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/

相关文章:

ios - 测试私有(private)@IBOutlets 和@IBActions

ios - 是否可以在 iOS 中的所有应用程序的屏幕信息上访问电池使用情况/时间?

objective-c - Objc : Class X is implemented in both Y and Z . 将使用两者之一。哪个是未定义的

iphone - NSMutableArray 问题

ios - 如何使用 swift 正确检查解析中的现有对象

ios - parse.com 推送通知框架不适用于 ionic 框架 Xcode 项目?

iphone - 在 Corona SDK 中,如果应用程序暂停,如何隐藏组?

iphone - 如何从应用程序将音乐文件添加到音乐播放器播放列表

iphone -- 在第二代 iPod Touch 上运行 XCode 4.2 和 iOS 5 SDK

ios - NSDateFormatter dateFromString 返回 null