Auto Layout keeps stretching UIImageView

前端 未结 5 1365
旧巷少年郎
旧巷少年郎 2021-01-03 18:44

I am using Auto layout and it\'s driving me crazy. I have done everything I could to prevent UIImageView from stretching all over. I have no idea why it does that. I tried u

5条回答
  •  盖世英雄少女心
    2021-01-03 19:18

    You'll want to make sure your UIImageView is set to clip to bounds. If not, the image will spill out of the view and will appear to not stretch correctly (even though in reality it is).

    In interface builder, make sure the Clip Subviews box is checked.

    enter image description here

    If you're not using interface builder, the following code will do the same thing:

    yourImageView.clipsToBounds = YES;
    

提交回复
热议问题