Reputation: 45
I want to display the float value in label using code
i tried with the following code but it doesn't work!!!! can you please help me out.
find my code for your reference:
UILabel * label;
float a;
a=2;
{ label = [self valueForKey:[NSString stringWithFormat:@"A:%d", a]];}
but it is giving a error as :SIGABRT
Upvotes: 0
Views: 136
Reputation: 1965
Use this
UILabel * label;
float a;
label.text=[NSString stringWithFormat:@"%f",a];
Upvotes: 0
Reputation: 29767
At first you should create label, then set formatted text to text
property, and after this show on your view (self.view assumes you use it into UIViewController)
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
[label setText:[NSString stringWithFormat:@"%f", a]];
[self.view addSubview:label];
[label release];
Upvotes: 3
Reputation: 19277
Something like this:
[label setText:[NSString stringWithFormat:@"A:%f", a]];
Upvotes: 0