繁体   English   中英

如何在Objective-c的页面视图控件中设置页码

[英]How to set page number in Page View Control in Objective-c

如何使用Objective-c中的Navigation项在每个页面的页面视图控件顶部设置页码?

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];

 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM