Setting UITextField constraints to continue in newline

Viewed 65

I've got UITextField widget inside a xib view controller with Scrolls layout, and I wish to set it with a proper string during runtime.

However, the string length may exceed the containing view controller and I'd like to define some constraint/limitation that when text exceeding about 80% of the containing view controller length, that the rest of the text will be written in newline (and if the rest will reach this limit, continue with the newline).

Here's the xib layout :

enter image description here

1 Answers

First, you will need to add a width constraint for the UITextField/UILabel, so it can stretch up to 80% of its superview. By holding the control key, drag the UITextField to its superview 1

Then, select Equal Widths 2

Final, select the width constraint that you have just created, in the right panel, modify the Multiplier to 0.8 3

Btw, if you use ScrollView, you should put your UITextField inside a UIView, and then put UIView inside ScrollView

Related