How to set page number in top of the page view control for every pages using Navigation item in Objective-c?
如何使用Objective-c中的导航项为每个页面在页面视图控件的顶部设置页码?
self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu to %lu)",(unsigned long)_dataArray.count,(unsigned long)_indexpath.row+1];
2 个解决方案
#1
0
Try this:
// config
UILabel *headlinelabel = [UILabel new];
headlinelabel.font = [UIFont systemFontOfSize:28];
headlinelabel.textColor = [UIColor redColor];
// set title string
headlinelabel.text = @"YourTitle";
[headlinelabel sizeToFit];
[self.navigationItem setTitleView:headlinelabel];
#2
0
Try this it work for me.
试试这个对我有用。
- (UIViewController *)pageViewController:(UIPageViewController
*)pageViewController viewControllerBeforeViewController:(UIViewController
*)viewController
{
NSUInteger index = ((PageViewController*) viewController).pageIndex;
indexpaths=index;
self.navigationItem.title=[NSMutableString stringWithFormat:
@"(%lu to %lu)",(unsigned long)_dataArray.count,
(unsignedlong)indexpaths+1];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController
*)pageViewController viewControllerAfterViewController:(UIViewController
*)viewController
{
NSUInteger index = ((PageViewController*) viewController).pageIndex;
indexpaths=index;
self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu to
%lu)",(unsigned long)_dataArray.count,(unsigned long)indexpaths+1];
if (index == NSNotFound)
{
return nil;
}
//self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu
to %lu)",(unsigned long)_dataArray.count,(unsigned long)indexpaths+1];
if (index == [self.dataArray count])
{
return nil;
}
index++;
return [self viewControllerAtIndex:index];
}
#1
0
Try this:
// config
UILabel *headlinelabel = [UILabel new];
headlinelabel.font = [UIFont systemFontOfSize:28];
headlinelabel.textColor = [UIColor redColor];
// set title string
headlinelabel.text = @"YourTitle";
[headlinelabel sizeToFit];
[self.navigationItem setTitleView:headlinelabel];
#2
0
Try this it work for me.
试试这个对我有用。
- (UIViewController *)pageViewController:(UIPageViewController
*)pageViewController viewControllerBeforeViewController:(UIViewController
*)viewController
{
NSUInteger index = ((PageViewController*) viewController).pageIndex;
indexpaths=index;
self.navigationItem.title=[NSMutableString stringWithFormat:
@"(%lu to %lu)",(unsigned long)_dataArray.count,
(unsignedlong)indexpaths+1];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController
*)pageViewController viewControllerAfterViewController:(UIViewController
*)viewController
{
NSUInteger index = ((PageViewController*) viewController).pageIndex;
indexpaths=index;
self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu to
%lu)",(unsigned long)_dataArray.count,(unsigned long)indexpaths+1];
if (index == NSNotFound)
{
return nil;
}
//self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu
to %lu)",(unsigned long)_dataArray.count,(unsigned long)indexpaths+1];
if (index == [self.dataArray count])
{
return nil;
}
index++;
return [self viewControllerAtIndex:index];
}