Resizing UITableViewCell Content When Delete Button Appears

Can I use autoresist masks to move my content so that the delete button does not close it? Googling told me that I need to set the UIViewAutoresizingFlexibleRightMargin auto- UIViewAutoresizingFlexibleRightMargin mask in my view. It seems to me that UIViewAutoresizingFlexibleWidth will make more sense; although I tried both of them and it doesn’t work.

The view I'm trying to compress is just a label, which is a subview of the contents of cellView. I'm not sure that the ContentView itself will automatically change when the delete button appears; but it seems that this is not so; otherwise, my autoresist mask should work.

If the presence of the delete button does not lead to resizing views; Anyway, can I do it manually?

+4
source share
3 answers

You must use UIViewAutoresizingFlexibleLeftMargin.

That's why. You want your content to move left, basically it looks like the delete button clicks the content on the left, out of it. flexibleLeftMargin basically means that your UILabel will remain fixed on the right side of your contentView. The reason you want this is because the delete button actually causes your ContentView to compress its width.

The autosave mask of your UILabel refers to how it behaves inside the contentView, and not to the cell.

Try it, it should work.

+4
source

This question is really old, but I feel that I have to answer everything the same way as soon as I found a solution myself.

Only the Resizable ContentView cell is displayed using the confirmation button. If you do not add your views (labels, image images, etc.) to cell.contentView instead of directly adding them to the cell, they will not be resized when the content is resized. In my case, I added it directly to the cell.

So, instead of doing something like:

 UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, width-10, 20)]; [nameLabel setFont:[UIFont boldSystemFontOfSize:16]]; [nameLabel setHighlightedTextColor:[UIColor whiteColor]]; [nameLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [nameLabel setTag:101]; [cell addSubview:nameLabel]; [nameLabel release]; 

you should:

 UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, width-10, 20)]; [nameLabel setFont:[UIFont boldSystemFontOfSize:16]]; [nameLabel setHighlightedTextColor:[UIColor whiteColor]]; [nameLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [nameLabel setTag:101]; [[cell contentView] addSubview:nameLabel]; // <<--- note the change in this line! [nameLabel release]; 

Hope this helps others who stumble on this issue.

+3
source

I am using iOS 7, I have the same problem. I use a separate xib for the UITableViewCell with auto layout turned on, so I just added another constraint on the shortcut so that it had a fixed gap on its right side.

+1
source

All Articles