Dalton Luedke
Dalton Luedke

Reputation: 51

Adding text to a label in Swift 2.2

I want to add words to an existing label without replacing them. For example if a label contains "hello" and I want to add "some other word(s)" but do so with out replacing "hello". So that the final text displayed will read "hello some other word(s)". Thanks to any one that helps!

Upvotes: 4

Views: 8159

Answers (1)

Luca Angeletti
Luca Angeletti

Reputation: 59496

It's easy. Given a label populated with "Hello" like this

let label = UILabel()
label.text = "Hello"

you can append more text using this code

label.text = (label.text ?? "") + " some other word(s)"

enter image description here

Upvotes: 7

Related Questions