Skip navigation
This discussion is archived

iPhone SDK: is there a toggle button?

8448 Views 6 Replies Latest reply: May 1, 2008 2:08 PM by leo4ever RSS
mhackney Calculating status...
Currently Being Moderated
Apr 29, 2008 6:41 PM
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 Calculating status...
    Currently Being Moderated
    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.
    MacMini/iPhone!, Mac OS X (10.5.2)
  • leo4ever Level 1 Level 1 (50 points)
    Currently Being Moderated
    Apr 30, 2008 10:34 AM (in response to mhackney)
    You can try using the segmented control with just one segement. I have never tried this but worth a try..
    Mac Mini, Mac OS X (10.5.2)
  • itripn Level 1 Level 1 (20 points)
    Currently Being Moderated
    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&
    Macbook Pro, Mac OS X (10.5.2)
  • leo4ever Level 1 Level 1 (50 points)
    Currently Being Moderated
    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
    Mac Mini, Mac OS X (10.5.2)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.