user564548
user564548

Reputation:

View doesn't fit in iOS Simulator

This must be a dumb question, but nevertheless I ask it. I don't have to explain (I think) that I'm just beginning with Xcode.

I have created this view in IB:

View in IB

And this is the result in the simulator:

Result in simulator

What can I do to fix this. It doesn't matter what device I choose (eg. 4S or 6) and device options are in sync (= same in IB and simulator).

NB: It is a new project and I have reset the auto-layout constraint to suggested settings.

Upvotes: 0

Views: 1407

Answers (4)

Mike Sand
Mike Sand

Reputation: 2770

You need to ensure your Auto Layout constrains are accurate.

  1. Make sure the view a controller is selected, and choose "Clear constraints"
  2. Select each of these items and choose "center horizontally in container"
  3. Select each of these, and add a constraint linking each to the one above. Note Xcode will fill in their current positions as default values.

Auto Layout tip: name your items in the document outline (the left in IB). Then when you examine constraints, you will be able to see which ones they are attached to by looking in the size inspector in the right.

Upvotes: 2

kygcoleman
kygcoleman

Reputation: 744

You need to go into attributes inspector for the view controller (right sided panel) go Simulated Metrics(should be at the top) -> Size and change it to "iPhone 4S" or "iPhone 5".

Upvotes: 0

YYfim
YYfim

Reputation: 1412

Your problem is that you are not using Autolayout functionality. I Would recommend reading about it, especially if you are new to iOS Dev. You really can do a lot if you are using IB (Storyboards) - check out this tutorial is should get you started

Autolayout is a system that helps you create apps for all different device dimensions.

Upvotes: 0

Adama
Adama

Reputation: 1097

Watch this video and get familiar with Auto-Layout. https://www.youtube.com/watch?v=G53PuA_TlXk

Letting Xcode use "suggested constraints" is nearly always useless and won't work like you expect. So you'll either need to position all of your elements programmatically by changing their frame, or, you need to set up proper auto-layout constraints.

Upvotes: 1

Related Questions