Johwhite
Johwhite

Reputation: 323

How can I make UITextField always centered on the screen?

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.

Upvotes: 0

Views: 545

Answers (4)

Ashish Kakkad
Ashish Kakkad

Reputation: 23872

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

Upvotes: 1

VictorG
VictorG

Reputation: 186

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

Upvotes: 2

Avijit Nagare
Avijit Nagare

Reputation: 8782

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

Upvotes: 1

RayChen
RayChen

Reputation: 1468

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

Upvotes: 0

Related Questions