user1118664
user1118664

Reputation: 45

displaying UILabel text using code

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

Answers (3)

Piyush Kashyap
Piyush Kashyap

Reputation: 1965

Use this
UILabel * label;

float a;

label.text=[NSString stringWithFormat:@"%f",a];

Upvotes: 0

beryllium
beryllium

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

fannheyward
fannheyward

Reputation: 19277

Something like this:

[label setText:[NSString stringWithFormat:@"A:%f", a]];

Upvotes: 0

Related Questions