Rob
Rob

Reputation: 8101

How to change view height based on device? (xcode)

I'm working on modifying this app, and it has a view that fills the screen. Unfortunately, this is all set statically in the interface builder.

Is there a button somewhere on XCode (I'm new to XCode) that will tell it to automatically fill the device screen?

If not, how can I change the height programmatically?

Thanks!

Upvotes: 0

Views: 5158

Answers (2)

manman
manman

Reputation: 5113

Set your controller's frame as you want it to be in Interface Builder. For example, if you're working on iPad simulator and want the view to be full screen, set x and y to 0 and set the width and height to 768 and 1024 on portrait or 1024 and 768 if you have selected landscape. I also suggest working with springs and struts which is easier to start with. For that you need to select your controller, and go to File Inspector tab on right and uncheck Use AutoLayout

enter image description here

No go to springs and struts tab, and make sure that you have set it to expand in both width and height while maintaining its distance from left, top, right, and bottom.

enter image description here

That would make your view resize itself depending on the device size.

Upvotes: 1

JustAnotherCoder
JustAnotherCoder

Reputation: 2575

I think what you are looking for is

CGRect screenBounds = [[UIScreen mainScreen] bounds];

Then you can set the view accordingly like so:

self.view.frame = screenBounds;

Upvotes: 0

Related Questions