如何在导航栏中创建下一个和上一个按钮,就像在iphone中的邮件应用程序中一样。 alt text http://www.freeimagehosting.net/uploads/4527ccc3d5.png
答案 0 :(得分:7)
使用下一个代码(注意您需要“prev.png”和“next.png”图片 - 箭头):
- (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;
}
}
}
编辑:更正了代码
答案 1 :(得分:1)
可以使用带有2个细分的UISegmentedControl
来实现。
将segmentedControlStyle设置为UISegmentedControlStyleBar
。
设置2 UIImage
向上和向下看。