Home Tutorial Iphone Examples iPhone UILabel Color

 
 

Share on Google+Share on Google+
iPhone UILabel Color
Posted on: April 28, 2010 at 12:00 AM
Advertisement
In this example we'll discuss about the UILabel class and it properties such as textcolor, shadowColor etc.. that customize the appearance of text in your iPhone applications.

iPhone UILabel Color

In this example we'll discuss about the UILabel class and it properties such as textcolor, shadowColor etc.. that customize the appearance of text in your iPhone applications.

Final application will look alike..

But first of all lets understand what is UILabel?

UILabel is class that implements a read-only text view, that means.. we can write multiple lines of static text on label in our applications. For example if you wanted to identify the use of text area in your app then you can simply place a UILabel over it with a message like "Enter your name" or "Password".

As UILabel provides you multiline texting feature, you can use it to provide the useful informations to a user. Such as about your company or product. One more thing is that it is not editable that means user can't edit it unlike UIText area. So it's generally used to show the static information.

Now, let's talk about the properties of UILabel.

UILabel class has number of properties like ... font, text, textColor, textAlignment & lineBreak etc... that allows to mould the presentation of text in any format. You can give diverse effect, highlighting, color, and shades to it. But in this example we are talking about couple of features like how to change the UILable text color in iPhone and label text in shadowColor.

Creating your first UILabel based application..

- Create a View based application in Xcode, assign a name to it and save the application.

- Open viewController.h file and create the IBOutlet and property for UILable. As we did in our application.

#import <UIKit/UIKit.h>

@interface labelsViewController : UIViewController {

IBOutlet UILabel* myLabel;

}

@property(nonatomic,retain) UILabel* myLabel;

- (IBAction)action:(id)sender;

@end

We are also creating a button action that will implement the method on clicking it.

In interface builder take a UILabel and write some text on it. You can also change that text in runtime using "myLabel.text = @"clicked";". Take a button create a connection to button action in file owner. Same for the UILabel connect it to IBOutlet "myLable" in file owner.

In viewcontroller.m file synthesize the myLabel and also release it in dealloc method.

To change the color or text, UILabel class provides a property called "textColor" using it we can change the color of text in label.

myLabel.textColor = [UIColor redColor];

"myLabel" is the reference type.

To set the shadow "shadowcolor". like....
myLabel.shadowcolor = [UIColor whiteColor];

Write both the methods on your button action and test the application. Hope the UILable tutorial will help you.

Download Code

Advertisement

Related Tags for iPhone UILabel Color:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 28, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com