如何在UIPageViewController中更改按钮名称

时间:2017-04-09 01:34:54

标签: ios objective-c swift uipageviewcontroller

我使用http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/

制作了与UIPageViewController相关的应用程序

当UI到达最后一页时,如何更改UIButton的标题,而UIButton位于包含UIPageViewController的UIViewController中?

由于

1 个答案:

答案 0 :(得分:0)

阅读完本教程后,您需要做什么:

  1. 为按钮标题添加PageContentViewController(标题文件)的属性
  2. @property NSString *buttonText;
    
    1. 在PageContentViewController(实现.m文件)中,在viewDidLoad方法中,设置按钮的标题:
    2. if (self.buttonText != nil) {    
         [self.button setTitle:self.buttonText forState:UIControlStateNormal];
      }
      
      1. 在故事板中,将按钮的插座添加到视图控制器,类似于您对titleLabel所做的操作,然后拨打插座"按钮"
      2. 最后,在ViewController.m的viewControllerAtIndex方法中,将pageContentViewController.buttonText设置为默认按钮文本或SPECIAL按钮文本。
      3. 为此,在设置页面索引之后,您可以执行以下操作:

        // other initialization
        pageContentViewController.pageIndex = index;
        if (index == [self.pageTitles count] - 1) {
           pageContentViewController.buttonText = @"Your special text";
        }
        

        因为按钮的自然文本只有在设置时才会被覆盖,所以只有当用户在最后一页时才应该更改文本!