Reputation:
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
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
Reputation: 12641
Try to allocate UILabel first then it may work..
Add following line above the code
lable=[[UILabel alloc]init];
Upvotes: 4
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