Morphley Morphley - 1 year ago 70
Swift Question

iOS User Interface without Storyboards: Change UITextField font and guarantee minimum characters for a textField Object

I didn't find an answer that solved my problems or that was explained in an easy way. So please don't give me any other stack overflow links because I realy read them and couldn't solve my problem. I also looked up in the documentation. Thanks for helping me out.

Im building an iOS app with SWIFT and don't use storyboards for the user interfaces. I created a LoginController with the UItextfield userName where a new user can enter his userName (see below : userNameTextField ). I changed the placeholder text to the String "Name".

Question1: How can I change the placeholder font and textsize. I want to have a bold placeholder text.

let userNameTextField: UITextField = {
let tf = UITextField()
tf.placeholder = "Name"
tf.translatesAutoresizingMaskIntoConstraints = false

return tf



Usernames must be at least five characters long before the registration can work. How can I guarantee this in my code. A kind of notification would be cool like Sorry you need at least 5 characters.
Can you please give me just a short example for one UiTextField Object ?


Answer Source
tf.font = UIFont.boldSystemFont(ofSize: 16.0)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download