0

I'm making an app in which I add people to a list by using a modal VC, that currently has only three text fields.

Problem: This is what I see in the interface builder, inside my Main.storyboard file:

enter image description here

I'm running Xcode version 6.2 (6C131e) and the app I'm making will be for iPod touch only, so I disabled auto-size classes. I'm expecting those text fields to be at the center of the screen (same distance from text field lateral border to screen edges). Instead I get this on the simulator:

enter image description here

Question: How can I set an equal distance for both the sides of text fields? Any resource like tutorials, examples, guides are appreciated, because I am a very beginner in iOS programming. If this can be done with interface builder for me is better then programmatically.

Johwhite
  • 323
  • 4
  • 18

4 Answers4

2

As simple as this:

enter image description here

In the Align menu from the bottom of interface builder if you set this constraint to 0 it will be the center of the view

Community
  • 1
  • 1
VictorG
  • 186
  • 6
  • I accepted your answer because it's the most correct for the question. I tried to do only this and i obtain what i want. Thank you! – Johwhite Aug 06 '15 at 10:27
1

enter image description here

Select First Textfield

Goto Pin-> Uncheck constraints to Margin-> Select Top,Left,right constraints with default value(or change if want ex. 16 left,right,30 top).

For Second and Third Textfield Goto Pin->Uncheck constraints to Margin->Select Top,Left,right constraints

Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
  • If i simply do: pin>width and: pin>height It hasn't the same effect? The purpose of this is to give a precise constraint to each textfield? – Johwhite Aug 06 '15 at 10:35
  • Yes you are right. then you have to apply align->Leading and trailing Edges constraints.but they will be in fixed width in landscape and iPad. hope this will help you. – Avijit Nagare Aug 06 '15 at 10:41
1

If you are not using Autolayout then the default Autoresizing property should be

enter image description here

Change the Autoresizing property to this :

enter image description here

Check this question : Any other method to resize views, other than Auto-layout

Community
  • 1
  • 1
Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
  • I was confused on what you asked about autolayout, because infact i'm using it in the project! Sorry for giving wrong informations! Thank you for the answer, it helps me the same. – Johwhite Aug 06 '15 at 10:22
  • @Johwhite Oh! you said I am not using autolayout. So, I have added this answer. Else other answers set constraint to Horizontal Center and it will work. – Ashish Kakkad Aug 06 '15 at 10:24
0

I just take horizontally as example. You have two ways to make it in the centre. 1. Make leading space equals trailing space.
enter image description here

  1. Make the textfield center horizontally in container view. enter image description here

I recommend you can study with raywenderlich tutorial. http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

RayChen
  • 1,417
  • 2
  • 17
  • 36