Objective-c 如何在页面视图控件中设置页码
How to set page number in Page View Control in Objective-c
如何使用 Objective-c 中的导航项在每个页面的页面视图控件顶部设置页码?
self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu to %lu)",(unsigned long)_dataArray.count,(unsigned long)_indexpath.row+1];
试试这个:
// 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];
试试这个对我有用。
- (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];
}
如何使用 Objective-c 中的导航项在每个页面的页面视图控件顶部设置页码?
self.navigationItem.title=[NSMutableString stringWithFormat:@"(%lu to %lu)",(unsigned long)_dataArray.count,(unsigned long)_indexpath.row+1];
试试这个:
// 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];
试试这个对我有用。
- (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];
}