I'm very new to Swift, like one week new and I'd like to come up with a 100% width UITextField. The expected result is that the text field should be 100% of the screen's width.
This is what I've done for iPhone 5 displays having a 320px vertically centered TextField.
That looks as expected, but when I'm going on iPhone 6, this happens:
How is it possible to make this 100% of the screen's width? As I can only see fixed width inputs in size inspector.
You should not specify the width but the leading and trailing space of the textfield to its superview:
UITextField
you want to alignPin
iconwhich will result in the TextField to span the entire width on every screen:
Note that you sometimes have to specify the view you want to set the space relative to:
You can use auto layout and constraints,
if you wish, you can do it manually using code:
//full screen size
let screenWidth = UIScreen.mainScreen().bounds.width
textInput.frame.size.width = screenWidth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With