Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 04-25-2009, 08:43 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 103
WeatherMan is on a distinguished road
Default Can I make a button stay highlighted like it is selected? Here is my code!

I am using 3 buttons as selectors and want the last one pressed to stay highlighted. I used this code which seems like it should work but does not:

Code:
UIButton *buttonClicked = (UIButton *)sender;
UIImage *imageOfClicked = [buttonClicked imageForState:UIControlStateHighlighted];
[buttonClicked setImage:imageOfClicked forState:UIControlStateNormal];

Anyone know why this does not cause the normal state to be the highlighted state?
WeatherMan is offline   Reply With Quote
Old 05-15-2009, 02:16 AM   #2 (permalink)
Apple Evangelist
 
sukumar_77's Avatar
 
Join Date: Aug 2008
Location: Mumbai
Posts: 203
sukumar_77 is on a distinguished road
Default

Try following:

Code:
[button setImage:imageOfClicked forState:UIControlStateSelected];
[button setSelected:YES];
__________________
- Sushil
sukumar_77 is offline   Reply With Quote
Old 06-04-2009, 02:18 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: Winnipeg, Canada
Posts: 6
mike62 is on a distinguished road
Lightbulb

I found this post, and a couple others, on this topic and dug into it a bit since I need checkboxes. This method should work for what you're doing as well. Thanks sukumar, your post pointed me in the right direction, though I found I didn't need this line:
Code:
[button setImage:imageOfClicked forState:UIControlStateSelected];
I just set the images for the button in Interface Builder, then used
Code:
[button setSelected:YES];
to change its "mode".

Have a look at my tutorial on how to create a simple checkbox in Interface Builder. There is source code in the form of a working Xcode project.
mike62 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
9 members and 352 guests
.Snipe, BSH, Cee Oasis, givensur, guusleijsten, HemiMG, NSString, Paul Slocum, SillyHoney
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0