views:

23

answers:

2

How do you set an iPhone UIButton to the selected state, i.e. where it is blue highlighted?

A: 

Set the selected property to YES like this :

theButton.selected = YES;
MathieuF
A: 

I'd recommend for simple questions like this you start by looking at the documentation provided by apple. Every class has a reference document which should be your first port of call.

UIButton

Granted UIButton's documentation does not actually cover the selected property but that is where you check the documentation for the classes it inherits from.

Inherits from UIControl : UIView : UIResponder : NSObject

And in this case it is UIControl that has the property you are looking for.

myButton.selected = YES;
willcodejavaforfood
Hi - it does seem obvious.
WaterBoy
But I did check the documentation and I did use that line of code but it didn't work. So I presumed there was some kind of limitation?
WaterBoy
As a little more background, there is a second thread operating in the background which is communicating across a stream. So i think the issue is updating the GUI, even though it is the main thread which picks up the button press event, I can't seem to hold the button in a pressed state (is that the same as selected?)
WaterBoy