简体   繁体   中英

Width and height not adjusting with Xcode Auto Layout

I have created an interface for my app in Storyboard under the Any x Any layout setup, when I run my app the layout is still sized for the square Any x Any and not the phone screen. I want the app to adjust to all sizes and not use a set layout for set screen sizes. How can I do this?

Here are pictures to show my design, and the outcome of running the app.

Storyboard View

Simulator View

The table view is also cut off here

what exactly are you trying to achieve? Your tableview to be entirely on the screen, so not scrollable?

If so, then you should override the layout of your tableview and its corresponding cells. As those cells (and the number of them) define the height of your tableview.

From what I can see it appears that you have manually added a UINavigationBar. I personally find it much easier to embed your view controller into a navigation controller. This will provide you with a navigation bar that will automatically resize depending on the hardware, or size class, of the device. To embed it go to: Editor -> Embed in -> Navigation Controller.

Your TableView seems to be fully in the screen as well? If you have layout issues with your cells not adjusting then I will be more than happy to help you once you clarify what is not quite right.

Hope this helps.

If your ViewController is subclass of UIViewController then add leading, trailing ,top and bottom constraints to UITableView , and contains to your custom navigation bar. or If its subclass of UITableViewController . No need to add any constraints. Just embed your TableViewController into NavigationController .

Hope this will help you

Yep. Been there, done that. Just because something is centered in the Any x Any view in interface builder does not mean it will also be centered eg in an iPhone simulator. You always need to make your layout choices explicit with constraints, ie in the this case add a "center horizontally in superview" constraint or align the right and left edge with the superview (I really would need to know more about your view controller in interface builder to tell you exactly).

Are you familiar with constraints or should I add some more detail on how to solve this?

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