views:

237

answers:

3

I'm using label of a button to send a value into a function. However, I want the button to be invisible. I have the background color turned of in IB, and the text color is also set to nothing, but the text still shows up on the button.

Is there another way to have a clear button that sends a value when it's clicked?

If I could just turn off / hide the text on the stock UIButton that would be perfect...

Thanks,

Doug

+1  A: 

you can do something like

MyButton.titleLabel.alpha = 0.0;
mihirpmehta
If the button is being passed to the method as (id)sender, how would you restate this?[sender titleLabel.alpha = 0.0] does not work...sender.titleLabel.alpha = 0.0 does not workthis.titleLabel.alpha = 0.0 does not work...
dbonneville
type cast it... then it may work...
mihirpmehta
But how do you cast a sender so that I can access as MyButton?
dbonneville
A: 

Note: while some may find it overly pedantic the question should not be how can I hide the text of a label in Objective C but how do I hide the text of a button in cocoa touch.

Also agreeing with marcc, using the label of a button to send a value into a function sounds a bit iffy. May we ask for context as why you want an invisible button? Or do you just want a transparent button with no text? If so does it have any images? How would the user have any clue of what it does?

Roman A. Taycher
I'm creating a visual that functions a bit like a progress meter with very customized art in the background. When you click button 5, buttons 1-4 light up. The artwork glows and bleeds beyond button boundaries.Therefore, I was using an invisible button to simply update the UIImageView in the background. I was using the Title attribute to pass in the a value, like "02" and "03". I then create a concatenated string and use it to set the image to the background.
dbonneville
Works perfect, except that the highlight state blinks a little bit of white text.I'm new to Obj-C, and am used to just hacking away in Perl, JavaScript. It seems like I should be able to create a new button of my own, with has some kind of title property I could pass (in javascript, it would be simple like button.someValue = "05" and then pass button.someValue into a method. But, I don't know how to do that here.
dbonneville
I have about 70 states that all need to fit on the screen with the same glowing bleed, so using IB to position the buttons over the custom artwork states seems like the best way to go.So, back to the problem: I need invisible buttons that can pass an attribute (or just pass their entire self which is what I think happens with '(id)sender') so I can access it and concatenate a variable with which to reference an image to slap into an UIImageView.
dbonneville
+2  A: 

[MyButton setHidden:YES] to Hide And

[MyButton setHidden:NO] to Unhide the button.

use:

[MyButton setEnable:NO];
[MyButton setHighlighted:YES];
[MyButton setEnable:YES];

to Hide

And

[MyButton setEnable:NO];
[MyButton setHighlighted:YES];
[MyButton setEnable:NO];

to unhide.

Manjunath
The code is valid like this:[sender setHidden...but it does not stop the blinking. I added YES to an on Touch Down, and then added NO on the on Touch Up, but it still blinked the active state text.If I don't add the NO to the on Touch Up, it doesn't blink...but then I can't click the button any more cause it's gone!If I could get at the alpha of the labelText, that might work, but I can't see how.
dbonneville
use:[MyButton setEnable:NO];[MyButton setHighlighted:YES];[MyButton setEnable:YES];to HideAnd[MyButton setEnable:NO];[MyButton setHighlighted:YES];[MyButton setEnable:NO];to unhide.
Manjunath
Just Checkout the edited answer.
Manjunath
I only have access to the button via sender, which does not work. I can't say "MyButton", since the function receives only (id)sender. Is there some way to do what you are saying?
dbonneville
How to I cast the sender to work as MyButton and keep it that way so that your code example works?
dbonneville
(UIButton*)sender
Manjunath