Resize UITableViewCell content when delete button shows up

前端 未结 3 1417
无人共我
无人共我 2020-12-18 10:55

Is there any way to use autoresizing masks to move my content so that the delete button doesn\'t cover it up? Googling has told me that I need to set an autoresizing mask of

3条回答
  •  星月不相逢
    2020-12-18 11:13

    This question is really old but I feel I should answer this anyway since I just found the solution myself.

    Only the cell's ContentView gets resized with the confirmation button is shown. If you don't add your views (labels, imageviews, etc...) to the cell.contentView instead of adding them to the cell directly then they won't be resized when the contentView is resized. In my case, I was adding it to the cell directly.

    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 do:

    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 upon this issue.

提交回复
热议问题