Justin Rose
Justin Rose

Reputation: 1185

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

I've come across this problem when creating UIImageViews, on the iPhone 6, it fits nicely, but on the 4s, it is huge!, is there a way to add some logic in the ViewDidLoad to change the px size of whatever it is, whether it's a sprite, image, label, etc. ?

Upvotes: 0

Views: 134

Answers (2)

Michael Mooney
Michael Mooney

Reputation: 347

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
}

Upvotes: 0

Name
Name

Reputation: 179

Just use auto layout and size classes (You access them in IB down and select the sizi class for iPhone)

Upvotes: 1

Related Questions