user1396086
user1396086

Reputation:

UILabel is not giving text on logs when NSLog is applied on it.?

My code is as follow and it is not working . If u found any mistake in it please tell me.

    name=@"Hello";
 label.backgroundColor=[UIColor clearColor];
 label.frame=CGRectMake(80, 23, 170, 20);
 label.textAlignment=UITextAlignmentCenter;
 label.textColor=[UIColor whiteColor];
 label.font=[UIFont boldSystemFontOfSize:12];

 [label setText:[NSString stringWithFormat:@"Welcome, %@",name]];

  NSLog(@"label text in view did load method %@",label.text);

Upvotes: 0

Views: 629

Answers (4)

Mutawe
Mutawe

Reputation: 6524

try this

UILabel * label = [[UILabel alloc] init];

Upvotes: 0

Mani
Mani

Reputation: 1841

    UILabel *label=[[UILabel alloc]init];
    NSString  *name=@"Hello";
    label.backgroundColor=[UIColor clearColor];
    label.frame=CGRectMake(80, 23, 170, 20);
    label.textAlignment=UITextAlignmentCenter;
    label.textColor=[UIColor whiteColor];
    label.font=[UIFont boldSystemFontOfSize:12];
    [label setText:[NSString stringWithFormat:@"Welcome, %@",name]];
    [self.view addSubview:label];

    NSLog(@"label text in view did load method %@",label.text);

Upvotes: 0

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

Try to allocate UILabel first then it may work..

Add following line above the code

lable=[[UILabel alloc]init];

Upvotes: 4

WrightsCS
WrightsCS

Reputation: 50697

Make sure you are creating an instance of label:

UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];

Even though you have defined label in your header does not mean you are initializing it. Use the above statement in before you set the properties of the label, then you will see the rsults you are expecting.

Upvotes: 0

Related Questions