Auto Layout keeps stretching UIImageView

前端 未结 5 1363
旧巷少年郎
旧巷少年郎 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 18:57

    You can try to add UIImageView programmatically. Call this code in your viewDidLoad method or where you want.

    UIImageView *yourImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50.0f, 50.0f, 320.0f, 320.0f)]; // x and y coordinates, width and height of UIImageView
    [yourImageView setImage:[UIImage imageNamed:@"your_image.png"]];
    [yourImageView setContentMode:UIViewContentModeCenter]; // you can try use another UIViewContentMode
    
    [self.view addSubview:yourImageView];
    

提交回复
热议问题