Следующая и предыдущая кнопка как почтовое приложение в iPhone

Как создать следующую и предыдущую кнопку в панели навигации как в почтовом приложении в iPhone. alt text

6
задан Glorfindel 31 July 2019 в 11:08
поделиться

2 ответа

Используйте следующий код (обратите внимание, что вам нужны изображения «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;
        }
    }
}


EDIT : исправлен код

7
ответ дан 16 December 2019 в 21:34
поделиться

Это может быть реализовано с помощью UISegmentedControl с 2 сегментами.

Установите segmentedControlStyle как UISegmentedControlStyleBar .

Установите 2 UIImage для просмотра вверх и вниз.

1
ответ дан 16 December 2019 в 21:34
поделиться
Другие вопросы по тегам:

Похожие вопросы: