5

I am a beginning iPhone developer. I want to create a UILabel programmatically, and I want to know all of the properties and functionality of the UILabel class.

Undo
  • 25,519
  • 37
  • 106
  • 129
Gopal
  • 59
  • 1
  • 1
  • 2

4 Answers4

15
UILabel *label = [[[UILabel alloc] initWithFrame:...] autorelease];
// Do some stuff
[self.view addSubview:label];

UILabel reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html

Ben Wheeler
  • 6,788
  • 2
  • 45
  • 55
unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62
10

Use this code.

UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;    
[self.view addSubview:lbl1];
lbl1.text= @"TEST";
D.M Patel
  • 145
  • 1
  • 7
3

Conveniently, Apple provides exactly that right here:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html

For any question of this nature, simply go to Google, type in "*Something* Class Reference" (where *Something* should be replaced with "uilabel" or "nsstring" or some such objective c class) and follow the result from developer.apple.com.

Andrew
  • 466
  • 2
  • 7
  • 22
  • 1
    The class reference does not tell a person how to create the object. It is full of hugely useful information, but for a "beginning iPhone developer" it is not sufficient. – Tony Adams Apr 03 '12 at 14:17
  • Aye, my answer is missing the first part of his question, though that information that the class reference is full of answers the second part of his question, pertaining to the class's properties. I believe ssteinberg's answer will suffice quite thoroughly. – Andrew Apr 03 '12 at 17:54
3

A quick way to get what you seek:

Control-click (or right-click) on the on the class type (UILabel in this case) and pick "Jump to Definition". XCode will take you directly to the header file where all is officially declared.

You could also pick "Find Text in Documentation" to go to the XCode document for the class.

(If there are categories or other variations available, you will have to pick "Interface UILabel".)

Walt Sellers
  • 3,806
  • 30
  • 35