Changing Text in an Existing Label

Download ios eBook

Example

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];

Stats

Contributors: 7
2016-08-01
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook