Xcode Iphone SDK – Use Variable for UIButton setTitle


I’m learning Xcode to create Iphone, Ipod Touch and Ipad applications. When I was playing around adding some UIButtons I was wondering how to use a variable instead of static text for the button title.

It took me houres to figure it out but here is the code!

{code type=xml}

// Static text

[myButton setTitle:@” Click Me !” forState:UIControlStateNormal];

// Variable (number )

[myButton setTitle:[NSString stringWithFormat:@” Click Me %i !”, number] forState:UIControlStateNormal];