Changing Text in an Existing Label

suggest change

Changing the text of an existing UILabel can be done by accessing and modifying the text property of the UILabel. This can be done directly using String literals or indirectly using variables.

Setting the text with String literals

Swift

label.text = "the new text"

Objective-C

// Dot Notation
label.text = @"the new text";

// Message Pattern
[label setText:@"the new text"];

Setting the text with a variable

Swift

let stringVar = "basic String var"
label.text = stringVar

Objective-C

NSString * stringVar = @"basic String var";

// Dot Notation
label.text = stringVar;

// Message Pattern
[label setText: stringVar];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents