如何更改 UIPageViewController 中的按钮名称
How to change button name in UIPageViewController
我有 UI页面ViewController 相关应用程序使用 http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
如何在 UI 到最后一页时更改 UI 按钮的标题,并且 UI 按钮在 UIViewController 其中包含 UIPageViewController?
谢谢
阅读教程后,您需要执行以下操作:
- 为按钮标题添加 属性 PageContentViewController(header 文件)
@property NSString *buttonText;
- 在 PageContentViewController(实现 .m 文件)的 viewDidLoad 方法中,设置按钮的标题:
if (self.buttonText != nil) {
[self.button setTitle:self.buttonText forState:UIControlStateNormal];
}
- 在情节提要中,将按钮的出口添加到视图控制器,类似于您为 titleLabel 所做的,并将出口命名为 "button"
- 最后,在 ViewController.m 的 viewControllerAtIndex 方法中,将 pageContentViewController.buttonText 设置为默认按钮文本或特殊按钮文本。
为此,在设置页面索引后,您可以这样做:
// other initialization
pageContentViewController.pageIndex = index;
if (index == [self.pageTitles count] - 1) {
pageContentViewController.buttonText = @"Your special text";
}
因为按钮的自然文本只有在设置后才会被覆盖,所以它应该只在用户在最后一页时更改文本!
我有 UI页面ViewController 相关应用程序使用 http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
如何在 UI 到最后一页时更改 UI 按钮的标题,并且 UI 按钮在 UIViewController 其中包含 UIPageViewController?
谢谢
阅读教程后,您需要执行以下操作:
- 为按钮标题添加 属性 PageContentViewController(header 文件)
@property NSString *buttonText;
- 在 PageContentViewController(实现 .m 文件)的 viewDidLoad 方法中,设置按钮的标题:
if (self.buttonText != nil) { [self.button setTitle:self.buttonText forState:UIControlStateNormal]; }
- 在情节提要中,将按钮的出口添加到视图控制器,类似于您为 titleLabel 所做的,并将出口命名为 "button"
- 最后,在 ViewController.m 的 viewControllerAtIndex 方法中,将 pageContentViewController.buttonText 设置为默认按钮文本或特殊按钮文本。
为此,在设置页面索引后,您可以这样做:
// other initialization pageContentViewController.pageIndex = index; if (index == [self.pageTitles count] - 1) { pageContentViewController.buttonText = @"Your special text"; }
因为按钮的自然文本只有在设置后才会被覆盖,所以它应该只在用户在最后一页时更改文本!