- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
iOS - Labels
Use of Labels
Labels are used for displaying static content, which consists of a single line or multiple lines.
Important Properties
- textAlignment
- textColor
- text
- numberOflines
- lineBreakMode
Add a 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
When we run the application we'll get the following output −
ios_ui_elements.htm
Advertisements