简体   繁体   中英

UIImageView ignores changes in contentMode

I'm absolutely stumped with this sizing bug I have. I have a UIImageView and a UITableView in my view layout. The UIImageView is set to Aspect Fit in IB, and it behaves as I want it to when i set the image using IB. but when I set the image programmatically, it resizes the view incorrectly.

I've tried everything I can think of to get this to appear correctly in the simulator and nothing comes out right.

bannerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
bannerView.image = banner;
bannerView.frame = CGRectMake(0,0,320,80);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
self.tableView.frame = CGRectMake(0,80,320,380);

Now the really interesting thing is that even though by the way I am constructing their frames, the tableview in this code should be directly below the image view. In reality, it is not. The table view doesnt move from where I had placed it in IB (with that exact frame size and coordinates), but the image view is way smaller for some reason.

Pleas help, this doesn't make any sense to me why this doesn't work

Ok, it seems the problem was in IB I had in the autosizing section for the view, all of the arrows were checked, when I only needed the top and left ones checked to keep it aligned

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM