Search code examples
iosxcodeuitextfielduilabeltextfield

2 TextField with 1 label in UIView


I am very new to programming and I was wondering how I can put the information of 2 textField in 1 single label with a space between them. Let's say put the first name and the last name.


Solution

  • So you have two text fields and one label, and I guess you have the outlets of them like this

    @IBOutlet weak var field1: UITextField!
    @IBOutlet weak var field1: UITextField!
    @IBOutlet weak var label: UILabel!
    

    To put the text of two text fields inside the label do this

    label.text = "\(field1.text) \(field2.text)"
    

    I hope it will help.