开发者

How to resize UITableViewCell Background in editing mode

开发者 https://www.devze.com 2022-12-22 18:49 出处:网络
I\'ve a table view with a custom image background of each cell. In normal mode the background is perfect and fill all the cell. When tableView enter in editing mode the \"-\" button appear on left and

I've a table view with a custom image background of each cell. In normal mode the background is perfect and fill all the cell. When tableView enter in editing mode the "-" button appear on left and all the object are indented and in the left I've problem with background: there a white area. Can anyone help me? The background image is big enough to fill all the cell but its moved in editing mode. Can I solve it? thanks a lot!

Update:

I used this code in my UITableViewCell subclass:

- (void) layoutSubviews
{

     UII开发者_开发知识库mage *backgroundImage = [UIImage imageNamed:@"sfondoCella2.png"];
     UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.bounds];
     bgView.image = backgroundImage;
     self.backgroundView = bgView;
     [bgView release];

}

To set background and appranetly works well in normal mode but when you go in editing mode all goes wrong: the circulare red delete button not appear and the indentetion of the cell (perfect with the background setted in IB) are not correct.


I don't think that there is a way to add a background image through IB. Instead, I am assuming you are just adding a UIImage subview.

I've added background images to table cells in code and I don't have the problem that you describe.

UIImage *backgroundImage = [UIImage imageNamed:@"my-bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.backgroundView.frame];
bgView.image = backgroundImage;
cell.backgroundView = bgView;
[bgView release];

Ideally you can do this in a custom UITableViewCell's layoutSubviews method and then tell IB that that is the class for your cell.

By extending UITableViewCell you have the ability to override the following methods and have control over exactly how the cell should look when in edit mode or selected.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
- (void)setEditing:(BOOL)editing animated:(BOOL)animated


You probably added you image view as a subview of the contentView of the UITableViewCell. You need to set your image view as the backgroundView of the UITableViewCell.

The backgroundView doesn't move in edditing mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消