views:

39

answers:

1

Hello all.

In my app i need to assign a string as a title for the uibutton.

How can i do this.For example

NSString *date=[[NSString alloc]initwithString:@"Todays Date"];
//am trying to assign the date content as a title for my button

[Button setTitle:date state:ForNormalSatate];

How can i set title as "Todays Date" for the button

+1  A: 

The syntax for setting a button title is:

[myButton setTitle:date forState:UIControlStateNormal];

Or are you more interested in getting the date as a string ? Look up the documentation for NSDateFormatter. If you have trouble with it, search StackOverflow for it.

BTW 1: Don't forget to release your date string.

BTW 2: Please accept answers to your old question.

DarkDust
i donno how to accept the answer even am searching it and i more thing is that i need to assign title as the content in the string date not date as title.I tried the solution u were given but i didnt succeeded.
iphoneStruggler
you click on the tick next to the answer
Joshua
@iphoneStruggler: What exactly do you mean with "didn't succeed" ? Do you get an error message ? If yes, which ? If not, try to also set the button title for the most important other UIControlStates, like disabled and selected.
DarkDust
i didn't get any error but i didnt get what i want s a title [btnDate1 setTitle:date forState: UIControlStateNormal]; It is showing tittle as date but i want title as "Todats date"
iphoneStruggler
Now *that's* a completely different beast :-) Please ask a new question, where you only concentrate on that point: *"How do I turn an NSDate into the string* Today *if it is today ?"*
DarkDust