6

如何在导航栏中创建下一个和上一个按钮,就像在 iphone 的邮件应用程序中一样。 替代文字

4

2 回答 2

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;
        }
    }
}


编辑:更正了代码

于 2010-06-30T06:46:23.307 回答
1

它可以通过使用UISegmentedControl2 个 Segments 来实现。

将 segmentedControlStyle 设置为UISegmentedControlStyleBar.

设置 2UIImage向上和向下看。

于 2010-06-30T06:30:10.613 回答