Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oceandrive

macrumors newbie
Original poster
Nov 17, 2008
28
0
Case:

I have 9 different buttons (Can grow) with images on them. I want to have a single method to handle the action for all. Is there a way for me to know which button is pressed.

The Button Tag does not work for me because it taken only Integers and in my case I want to pass a text (Ex: Multiple, divide, add, sub, doubleAdd).

I will not have any title on my buttons, just image buttons.

Thanks for the help.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
The Button Tag does not work for me because it taken only Integers and in my case I want to pass a text (Ex: Multiple, divide, add, sub, doubleAdd).
Do a mapping between the integers and the text. I.E. Multiply = 0, Divide = 1, Add = 2. Then set up an array of the text values and you can just retrieve them using objectAtIndex (where the index is your tag integer). Make sense?
 

oceandrive

macrumors newbie
Original poster
Nov 17, 2008
28
0
Yes sir....

Is there a way to set the font size for the title of the button to zero and use the [botton currentTitle]; ?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Is there a way to set the font size for the title of the button to zero and use the [botton currentTitle]; ?
No need to set the font size to zero. The image overrides the display of the title. So you can do:
Code:
[button setTitle:@"title" forState:UIControlStateNormal]
[button setImage:buttonImage forState:UIControlStateNormal]

and then later just retrieve the title with:
Code:
[button currentTitle]
 

oceandrive

macrumors newbie
Original poster
Nov 17, 2008
28
0
But in my interface builder when I select the Normal state and set the title and then select the image for my button, both the button and the image show up. Am I missing ?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
But in my interface builder when I select the Normal state and set the title and then select the image for my button, both the button and the image show up. Am I missing ?
Ah, I see what you mean. I had just tried it through the code. I don't think you can resize the font for the button in Interface Builder, so you're gonna have to use the code for whatever solution you decide to go with. I'd suggest not using the title, if you're not really intending on showing it anyways. Tags and a text-lookup-array would be my suggestion.
 

oceandrive

macrumors newbie
Original poster
Nov 17, 2008
28
0
ok I will use the tags and text lookup as u suggested. Thanks for the guidance.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You can set the font for a button in IB with the Font menu. Select the button and choose any item from the Font menu to change the font properties.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.