6 Replies Latest reply: May 1, 2008 2:08 PM by leo4ever
mhackney Level 1 Level 1 (10 points)
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)
  • Martin Norland Level 1 Level 1 (35 points)
    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.
  • leo4ever Level 1 Level 1 (50 points)
    You can try using the segmented control with just one segement. I have never tried this but worth a try..
  • mhackney Level 1 Level 1 (10 points)
    Thanks guys. I will use the UISegmentedControl for now.
  • itripn Level 1 Level 1 (20 points)
    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&
  • mhackney Level 1 Level 1 (10 points)
    Well, I am developing an audio recording application and the "standard" UI has toggle push buttons for record, pause, stop, play. The slider does not work well in this context.
  • leo4ever Level 1 Level 1 (50 points)
    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