JamesG
JamesG

Reputation: 1601

UITextField is bigger in Simulator

I'm having issues with my app design,

I have a Textfield on my view, and I positioned it and sized it (by dragging the element) to how I want it:

enter image description here

but when I view it in the simulator, it looks like this:

enter image description here

As you can see, it is bigger and unsightly. It goes right to the edge. How do I make sure that it will look the same across all iOS Devices and in the Simulator?

Bi of a noob here so hoping for a detailed answer.

Thanks.

P.s I'm using swift if there is any code requirements.

Upvotes: 0

Views: 54

Answers (2)

Vishnu gondlekar
Vishnu gondlekar

Reputation: 3956

In viewDidLoad try setting width of your textfield manually depending on the width of your screen. Try this out

var newFrame = textField.frame
newFrame.size.width = self.view.frame.size.width - 50 //change 50 according to your needs
newFrame.origin.x = 25 //should be half of constant set above so that textfield is in centre
textField.frame = newFrame

Upvotes: 0

Arch
Arch

Reputation: 127

Use auto layout. Auto layout is a way to add constraints to your UI allowing for you to fix problems like yours and allows for your to have a similar UI across multiple screen sizes with relative ease. http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2

Upvotes: 1

Related Questions