简体   繁体   中英

iPhone SDK: How to make a label view a cgpoint?

I have a CGPoint:

ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedX);

and i would like a label (xVelocityLabel) to view the "ballVelocity.x" value of the CGPoint. I have tried:

[xVelocityLabel setText:[NSString stringWithFormat:@"%@", ballVelocity.x]];

Thanks for your help because I am new to this.

Just change '%f' instead of '%@'.

[xVelocityLabel setText:[NSString stringWithFormat:@"%f", ballVelocity.x]];

I think it will be helpful to you.

[xVelocityLabel setText:NSStringFromCGPoint(ballVelocity)];

ballVelocity.x // this is a float value.

So you have to convert it in NSString before set it on UILabel.

for set a value on xVelocityLabel, the value should be in string format. see this conversion-

NSString *strNumber = [[NSNumber numberWithFloat:ballVelocity.x] stringValue];

[xVelocityLabel setText:strNumber];

Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM