下一个和上一个按钮就像 iPhone 中的邮件应用程序

发布于 2024-09-08 03:00:19 字数 177 浏览 0 评论 0原文

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

How to create next and previous button in navigation bar like in mail application in iphone.
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

記柔刀 2024-09-15 03:00:19

使用下一个代码(请注意,您需要“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;
        }
    }
}

编辑:更正了代码

Use the next code (notice that you need the "prev.png" and "next.png" images - 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 the code

纵山崖 2024-09-15 03:00:19

它可以通过使用具有 2 个段的 UISegmentedControl 来实现。

将segmentedControlStyle 设置为UISegmentedControlStyleBar

设置 2 UIImage 用于向上和向下查看。

It can be implemented by using a UISegmentedControl with 2 Segments.

Set the segmentedControlStyle as UISegmentedControlStyleBar.

Set 2 UIImage for up and down look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文