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

View Single Post
Old 05-25-2010, 12:05 PM   #7 (permalink)
officevalentin
Registered Member
 
Join Date: May 2010
Posts: 1
officevalentin is on a distinguished road
Default Excelent one small fix if you want to see only the image and no button backgr.

Quote:
Originally Posted by fiftysixty View Post
I struggled with this problem too once, and the solution I found was to make a UISegmentedControl with the custom image you want, and then setting the properties of the segmented control and creating a UIBarButtonItem with the segmented control as the custom view. The problem is still that it doesn't look like UIBarButtonItem with a string title, the background color is not the same, but it's better than using UIButton I think. Anyway, here is the code:

Code:
UIImage *customIcon = [UIImage imageNamed:@"yourImagepng"];
UISegmentedControl *customButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:customIcon, nil]];
customButton.segmentedControlStyle = UISegmentedControlStyleBar;
customButton.momentary = YES;
[customButton addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventAllEvents];
customBarButton = [[UIBarButtonItem alloc] initWithCustomView:customButton];
For some reason you have to use UIControlEventAllEvents for the segmented control, using UIControlEventTouchUpInside doesn't work.

UIImage *customIcon = [UIImage imageNamed:imgName];
UISegmentedControl *customButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:customIcon, nil]];
customButton.segmentedControlStyle = UISegmentedControlStyleBar;
customButton.momentary = YES;
[customButton addTarget:self action:@selector(buttonHint forControlEvents:UIControlEventAllEvents];
UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:customButton];
self.navigationItem.rightBarButtonItem = customBarButton;
//change the button frame
customBarButton.customView.frame = CGRectMake(0,0,40,0);
[customButton release];
[customBarButton release];

officevalentin is offline   Reply With Quote
 

» Advertisements
» Online Users: 488
19 members and 469 guests
Absentia, baja_yu, Brandt, BuzzingDanZei, Chickenrig, djbrooks111, Domele, dtkamal, iconomania, jbro, Kirkout, muhimranss, Paul Slocum, roelien, ryantcb, seecoolguy, SLIC, spiderguy84, za1407
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,549
Threads: 94,076
Posts: 402,719
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JMLdev
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.