简体   繁体   English

根据屏幕尺寸更改imageview,sprite,label等的尺寸

[英]Change size of imageview, sprite, label, etc. depending on screen size iOS

在iPhone 6上创建UIImageViews ,我遇到了这个问题,它非常适合,但在4s上,它非常大!有没有办法在ViewDidLoad添加一些逻辑来更改px大小,无论是图片,图片,标签等。

只需使用自动布局和尺寸类(您可以在IB中访问它们,然后为iPhone选择sizi类)

There are a few ways to do this, you could use auto-layout, or you can take a different route. 有几种方法可以执行此操作,您可以使用自动布局,也可以采用其他方法。 If you chose not to take auto-layout, I would recommend do this, however the down side is that there is a lot of programming. 如果您选择不采用自动布局,我建议您这样做,但是缺点是编程很多。

CGRect screenRect = [[UIScreen mainScreen] bounds]; 
CGFloat screenHeight = screenRect.size.height;

if (screenHeight == 480) {
    // do iPhone 4s stuff
} else if (screenHeight == 568) {
    // do iPhone 5, 5s, 5c stuff
} else if (screenHeight == 667) {
    // do iPhone 6 stuff
} else if (screenHeight == 736) {
    //do iPhone 6 plus stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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