Ame*_*eya 6 iphone uinavigationitem
如何在导航栏中创建下一个和上一个按钮,如在iPhone中的邮件应用程序中. alt text http://www.freeimagehosting.net/uploads/4527ccc3d5.png
使用下一个代码(注意您需要"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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:更正了代码
| 归档时间: |
|
| 查看次数: |
1993 次 |
| 最近记录: |