简体   繁体   中英

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
}

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