The next and previous buttons, for example, the email application on the iPhone

How to create the next and previous button in the navigation bar, for example, in the email application in iphone. alt text http://www.freeimagehosting.net/uploads/4527ccc3d5.png

+6
iphone uinavigationitem
source share
2 answers

Use the following code (note that you need the images "prev.png" and "next.png" - arrows):

- (void)addNextPrevSegmentedControl { // Prepare an array of segmented control items as images NSArray *nextPrevItems = [NSArray arrayWithObjects:[UIImage imageNamed:@"prev.png"], [UIImage imageNamed:@"next.png"], nil]; // Create the segmented control with the array from above UISegmentedControl* nextPrevSegmentedControl = [[UISegmentedControl alloc] initWithItems:nextPrevItems]; [nextPrevSegmentedControl addTarget:self action:@selector(nextPrevAction:) forControlEvents:UIControlEventValueChanged]; // Create the bar button item with the segmented control from above UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:nextPrevSegmentedControl]; // Add the bar button item from above to the navigation item [self.navigationItem setRightBarButtonItem:rightButton animated:YES]; // Release memory [rightButton release]; [nextPrevSegmentedControl release]; } - (void)nextPrevAction:(id)sender { if ([sender isKindOfClass:[UISegmentedControl class]]) { int action = [(UISegmentedControl *)sender selectedSegmentIndex]; switch (action) { case 0: // Prev break; case 1: // Next break; } } } 


EDIT : corrected code

+7
source share

It can be implemented using a UISegmentedControl with two segments.

Set segmentedControlStyle as UISegmentedControlStyleBar .

Set 2 UIImage to view up and down.

+1
source share

All Articles