tags:

views:

5419

answers:

3

Hi,

I have to add radio buttons in my iPhone application. For that I have got radio button image which is of round in shape. Can I add that image as a subview? and Can I add touchupinside event to UIImage?

A: 

You can try using the UIImageView class which just wraps a UIImage inside a UIView container. It supports the touchesBegan/Cancelled events which would be suitable I think.

You might also consider not using with a true radio button setup as you've described and instead going with a more iPhone-like approach--for instance, using a UITableView with cells corresponding to your radio selections and that toggle checked/unchecked on a touch. See the TouchCells example at the Apple iPhone dev site for an example.

drewh
I have created my radio button class by extending UIButton class, in my radiobutton class, how can I set the buttontype to UIButtonTypeCustom?.
saikamesh
Custom is the default button type.
Brent Royal-Gordon
Hi drewh, Finally I did what you suggested. I used UIImageView class and touchesBegan event. It works fine with no issues. Thanks a lot. Thanks to Brent too for giving me ideas.
saikamesh
+3  A: 

iPhone apps do not have radio buttons. The "iPhone-like" way to do this is either by using a picker view or by having several rows in a grouped table view with a check accessory on the chosen row.

If for some reason you really, really feel the need to have radio buttons, use a UIButton with a button type of custom. Set the empty circle as the image for the "normal" control state and the filled circle as the image for the "selected" state.

Brent Royal-Gordon
I tried what you said, It works fine. Initially the button looks like a round button, but the moment the button is clicked, the frame of the button appears(looks like a square button)
saikamesh
How Can I get rid of this thing?
saikamesh
If this one is not doable, the I have to try something else. So please tell me whether getting rid of this behavior is possible
saikamesh
You need to change the image for the Highlighted state as well. It should probably be a variant of the Selected button which suggests that you're in the middle of pressing the button.
Brent Royal-Gordon
To back up Brent's point on this answer, see Apple's iOS Human Interface Guidelines here, where they recommend against using radio buttons in favor of lists, pickers, or switch controls: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/HandleTasks/HandleTasks.html
Josh Brown
A: 

You can also create a UIWebView, load into it HTML that uses radio buttons, and then using the UIWebView delegat methods, monitor the radio value.

It's kind of a hack, but in some cases it's exactly what's called for.

August