Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 25, 2008, 02:37 PM   #1
Nonnus3G
macrumors member
 
Join Date: Jul 2008
iPhone SDK: anybody has a clue why UIButton.highlighted does not seems to work ?

hi

i have been trying to use ordinary round rect buttons to spare resources
i guess a standard button is easier on the system than an image based one,
am i wrong ?

i was trying to use them as radio buttons or on off ones,
where by clicking on a button it will get highlighted to indicate status

however, although i can set the highlighed state of any other button,
it does not work with the button that is being pressed,
after unpressing it always gets back to non highlighted state

is there a workaround ?

also i cannot seem to find a way to colour a UIButton,
it allows setting text color, background color, shadow but no button color

anybody has a suggestion ?
is there any way to achieve this or do i need to use image based buttons ?

thanks in advance for your help

nonnus
Nonnus3G is offline   0 Reply With Quote
Old Aug 10, 2008, 12:46 PM   #2
SPUY767
macrumors 68000
 
SPUY767's Avatar
 
Join Date: Jun 2003
Location: GA
I assume that you simply want them to appear as though they are highlighted when you have selected them? Essentially making them act like radio buttons, correct? If that is the case then I have a solution for you. It's just a few lines of code in your applicationDidFinishLaunhing method, and then you have to set the state of each button in it's target method, but that's easy enough.

Use this image as your UIButton's backgroundImage:

In your applicationDidFinishLaunching Method, add these lines (assuming three buttons):

Code:
//Sets the background images and title colors of the buttons to appear "highlighted" when they are selected
	[UIButton1 setBackgroundImage:[UIImage imageNamed:@"ButtonBack.png"] forState:UIControlStateSelected];
	[UIButton2 setBackgroundImage:[UIImage imageNamed:@"ButtonBack.png"] forState:UIControlStateSelected];
	[UIButton3 setBackgroundImage:[UIImage imageNamed:@"ButtonBack.png"] forState:UIControlStateSelected];
	[UIButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
	[UIButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
	[UIButton3 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
You will also have to add lines to each of the target methods to set the current button's control state to selected via the UIButton.selected = YES/NO; method.

Hope that helps.
Attached Images
 
__________________
Yo' mama's so STUPID, she went to Bangkok to get a TIE Fighter.
SPUY767 is offline   0 Reply With Quote
Old Aug 10, 2008, 11:11 PM   #3
Nonnus3G
Thread Starter
macrumors member
 
Join Date: Jul 2008
tx alot for replying

i had already started to use image based custom buttons
and have been using the selected property to set them as radio buttons
Nonnus3G is offline   0 Reply With Quote
Old Aug 11, 2008, 07:42 PM   #4
gralem
macrumors member
 
Join Date: Mar 2002
radio buttons...

The closest thing to a radio button on the iPhone is the UISegmentedControl. It holds state--works very well.
gralem is offline   0 Reply With Quote
Old Feb 5, 2009, 05:30 PM   #5
sbwoodside
macrumors newbie
 
Join Date: Feb 2009
use a timer

see How to make an iPhone button highlight (hold state)
sbwoodside is offline   0 Reply With Quote
Old Feb 5, 2009, 11:38 PM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
I believe the HIG recommends against leaving a UIButton selected to represent toggle state, in favor of using UISwitch.
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Apple's Work on Video Goggles Highlighted in Newly Granted Patent MacRumors MacRumors.com News Discussion 141 Dec 20, 2013 05:21 AM
iPhone 5S Changes Highlighted in New Rear Shell Comparison Photos MacRumors MacRumors.com News Discussion 161 Aug 27, 2013 09:09 AM
Why are some files highlighted red? Jayrcee Mac Basics and Help 4 Nov 7, 2012 05:08 PM
UIButton in subview can't work once the UITapGestureRecognizer added in superview cthesky iPhone/iPad Programming 2 Sep 30, 2012 02:41 AM
June 22 is release of iPhone 5, Cricket deal is clue PracticalMac iPhone 6 May 31, 2012 11:59 AM

Forum Jump

All times are GMT -5. The time now is 04:15 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC