When I click a button Its title should be hide. I do't want to set the title to empty string @"". So, How can i do this?
Why don't you want to set the title to an empty string? Simply store the value in a local field and set the button's title to @"" and everything will be fine.
In your .h:
NSString *someLocalField;
in your .m:
-(void)SomeButtonPressed {
someLocalField = someButton.text;
someButton.text = @"";
}
This way, if you ever need to restore the text of the button, you can do so:
someButton.text = someLocalField
If you want to do this for a bunch of buttons, you could always use an NSDictionary and associate the string values with the buttons.
I haven't tried this, but if you need the title text to stay the same, but still hide from a user you might be able to set the font color to [UIColor clearColor];
Just hiding the title sounds a bit odd and not very Apple interface like. You can also just set the button to be hidden and then the entire thing goes away. If you do want the title to be the only thing that goes away (keep in mind that the button will still work in this state, just not have a title) then you could always assign the background color someButton.currentTitleColor = someButton.backgroundColor;
should make the text vanish (you may need to set the shadow color as well).
If you want it to disappear when a finger is on the button,
[button setTitle:@" " forState:UIControlStateHighlighted];
If you want it to toggle between being displayed and not,
[button setTitle:@" " forState:UIControlStateSelected];
[button setTitle:@" " forState:UIControlStateSelected|UIControlStateHighlighted];
and then set button.selected = !button.selected
in the button action.
I'm using a single space instead of the empty string because sometimes the empty string has special handling which makes it equivalent to nil. If the empty string works, you can use that instead.