Reputation: 441
I have a view tableview which display custom cells. Those cells have a UIImageView which need to be scaled if the device is in landscape mode.
I set the autoresizingMask
of the tableView to UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
, did the same for my custom cells and the UIImageView.
My problem is that setting autoresizingMask
for the UIImageView changes the frame of the view without any rotation of the device needed.
This is my initialisation code for my UIImageView.
- (UIImageView *)bigImageView
{
if (!_bigImageView)
{
_bigImageView = [[UIImageView alloc] initWithFrame:(CGRect){2, [self.header getHeight], 272, 272}];
[_bigImageView setImage:[UIImage imageNamed:@"square.png"]];
[_bigImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[_bigImageView setBackgroundColor:[UIColor redColor]];
}
return _bigImageView;
}
The width should be 272 but changes automatically to 232.
The result expected with autoresizingMask
should be:
But I get:
The ratio is not respected anymore.
Upvotes: 0
Views: 1451
Reputation: 14063
This happens because every cell starts with a height of 44 points. You can check that in the init.
Maybe you can correct the size of the cell elements in drawRect:
or in layoutSubviews
.
Upvotes: 1