Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

iPhone SDK: is there a toggle button?

I need to make a toggle button - click once and it stays depressed, click again and it returns to normal state. I can't figure out how to do this with UIKit. Am I missing something?

Cheers,
Michael

Mac OS X (10.5.2)

Posted on Apr 29, 2008 6:41 PM

Reply
6 replies

Apr 29, 2008 8:04 PM in response to mhackney

The only thing built-in that does this is a UISwitch. What you could do is style a single button and link an action to it to store the toggle value, which would also change the style of the button.

I've not dug into the buttons stuff, but if there isn't advanced styling to simulate this, you could get around it with an ugly hack: switching between two buttons w/ linked actions (e.g. createGrayButton/createDarkGrayButton), and disabling animation during the 'hiding' transition.

My terminology is atrociously off, but you get the concept.

Apr 30, 2008 5:16 PM in response to mhackney

Forgive me, but I would question why you're not using a UISwitch? Based on your limited explanation of what you're trying to do, a UISwitch would be the iPhone way to do it. Why change it up? Why not leverage expectations of existing users based on the way the UI works?

Maybe you have a good reason -- I hope so, because a consistent UI is a real boon to users, new and old.

Cheers,
rjf&

May 1, 2008 2:08 PM in response to mhackney

Take a look at the UIBarButtonItem class. Apple provides system buttons with images for play, pause, forward, rewind etc. My suggestion would be to have a interface like the iPod where there are controls to stop, play, etc. If that doesn't work, just use a simple UIButton with Glass Style and change the tintcolor property. Ofcourse, you can change the appearance/text when user click on it. From my experience, a toggle button is just like a boolean and should be used in places where the needed answer is YES/NO. And if you had noticed (in iPhone), the UIswitches are mostly used for settings management and never actually used for controlling application.

Javid

iPhone SDK: is there a toggle button?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.