I have done something similar. I've added two UIButtons to a navigation item/bar by creating a UIView subclass that has two UIButtons in it. You can then do something like this:
MyUIViewSubclass *tempview = [[[MyUIViewSubclass alloc] initWithFrame:CGRectMake(234,4,84,30)] autorelease];
UIBarButtonItem newButton = [[[UIBarButtonItem alloc] initWithCustomView:tempview] autorelease];
[self.navigationItem setRightBarButtonItem:newButton animated:NO];
All you have to do is layout the buttons in MyUIViewSubclass
and you're good.
Also, I pass the ID of the target along in a customized init command to make for easier targeting of the buttons in the view. So for MyUIViewSubclass
instead of initWithFrame
, I have something like this:
- (id)initWithFrame:(CGRect)aRect andTarget:(id)newTarget {
if (self = [super initWithFrame:aRect]) {
UIButton *editbtn = [[[UIButton alloc] initWithFrame:fframe] autorelease];
[editbtn addTarget:newTarget action:@selector(MBEdit) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:editbtn];
[self setFirstbutton:editbtn];
[editbtn release];
UIButton *newbtn = [[[UIButton alloc] initWithFrame:fframe] autorelease];
[newbtn addTarget:newTarget action:@selector(MBNew) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:newbtn];
[self setSecondbutton:newbtn];
[newbtn release];
}
return self;
}