Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

iOS Labels

Use of Labels

Labels are used to display static content, including a single line or multiple lines.

Important Properties

Add the custom method addLabel

-(void)addLabel{

    UILabel *aLabel = [[UILabel alloc]initWithFrame:

    CGRectMake(20, 200, 280, 80)];

    aLabel.numberOfLines = 0;

    aLabel.textColor = [UIColor blueColor];

    aLabel.backgroundColor = [UIColor clearColor];

    aLabel.textAlignment = UITextAlignmentCenter;

    aLabel.text = @"This is a sample text\n of multiple lines.

    here number of lines is not limited.";

    [self.view addSubview:aLabel];

}

Update viewDidLoad in ViewController.m as follows:

- (void)viewDidLoad

{

    [super viewDidLoad];

    //The custom method to create our label is called

    [self addLabel];

    // Do any additional setup after loading the view, typically from a nib.

}

Output

Run the application and you will get the following output:

labelOutput