0

I am drawing a custom UIView in every table view cell like so:

    _checkboxView = [[[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 28.5, cell.frame.size.height - 33.5, 25, 25)] autorelease];
    _checkboxView.backgroundColor = [UIColor clearColor];
    _checkboxView.layer.borderWidth = 4.0f;
    _checkboxView.layer.borderColor = [[UIColor blackColor] CGColor];
    _checkboxView.layer.cornerRadius = 4.0f;
    [cell addSubview:_checkboxView];
    [cell bringSubviewToFront:_checkboxView];

This works perfectly, but when the phone is switched to landscape mode, the checkbox is in the wrong place, and goes near the middle of the table view cell. I need it to stay anchored to the right side of the cell using the constraints I made for portrait mode. Naturally, I would just go to the method:

-(void)viewWillLayoutSubviews

But how do I make sure that I am able to properly anchor the view for every UITableViewCell? I can't use interface builder (and thus Auto Layout) because the entire thing is built programatically. How would I get a handle of the specific cell it's looking at in this method?

4

1 回答 1

2

尝试autoresizingMask为该视图设置...

[_checkboxView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin];

享受编码......

于 2013-06-11T15:03:02.413 回答