How to set a CGFloat to a UILabel's text property
Asked Answered
D

2

18

I have a UILabel called optionsDisplayerBrushSizeLabel who's text property I want to set to a CGFloat: brushSizeVal. I understand that the text property needs to be a string but I don't know how to convert a CGFloat to an NSString.

Derickderide answered 30/12, 2009 at 4:46 Comment(0)
M
32

You can try:

[NSString stringWithFormat: @"%.2f", myFloat];
Merari answered 30/12, 2009 at 4:50 Comment(2)
I think there should [NSString stringWithFormat: @"%.2f", myFloat]; for floats.Ghassan
you are entirely correct, I've edited my answer, sorry, a typo.Merari
F
0

Tray this in swift

var a = String (stringInterpolationSegment:myFloat)
Faceless answered 4/6, 2015 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.