gpt4 book ai didi

iphone - UIPageViewController 的 NavigationBar 不显示标题

转载 作者:可可西里 更新时间:2023-11-01 05:45:09 25 4
gpt4 key购买 nike

UIPageViewController 的导航栏不显示页码作为导航栏的标题。

- (void)viewDidLoad {

[super viewDidLoad];

//modelArray holds the page numbers
modelArray = [[NSMutableArray alloc] init];

for (int index = 1; index <= totalPages; index++) {

[modelArray addObject:[NSString stringWithFormat:@"%i", index]];

}

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 45)];

navBar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

self.navigationItem.title = modelArray;

[self displayPageNumber:1];

thePageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal options:nil];

thePageViewController.delegate = self;
thePageViewController.dataSource = self;

thePageViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

contentViewController = [[ContentViewController alloc] initWithPDF:PDFDocument];
contentViewController.page = [modelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:contentViewController];
[thePageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:thePageViewController];
[self.view addSubview:thePageViewController.view];
thePageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);


[thePageViewController didMoveToParentViewController:self];

_toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 960, self.view.bounds.size.width, 45)];

_toolbar.barStyle = UIBarStyleBlackOpaque;

_toolbar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

[self.view addSubview:_toolbar];

[self.view addSubview:navBar];
}

- (void) pageViewController:(PageViewController *)pageViewController willTurnToPageAtIndex:(NSUInteger)pageIndex {
[self displayPageNumber:pageIndex + 1];
}


- (void) displayPageNumber:(NSUInteger)pageNumber {
self.navigationItem.title = [NSString stringWithFormat:
@"Page %u of %u",
pageNumber,
CGPDFDocumentGetNumberOfPages(PDFDocument)];
}

感谢您的帮助。

最佳答案

很简单。

这样做

_navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 45)];

_navBar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:[NSString stringWithFormat:
@"Page %i of %i",
pageNumber,
CGPDFDocumentGetNumberOfPages(thePDF)]];
[_navBar pushNavigationItem:title animated:NO];

希望对你有帮助。

关于iphone - UIPageViewController 的 NavigationBar 不显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com