iOS UILabel Changing Text in an Existing Label

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any iOS Question?