条纹iOS更改后退按钮标题

时间:2018-10-25 05:36:27

标签: ios swift xcode stripe-payments

有没有办法改变条纹取消按钮的标题?

Stripe PaymentMethodsController

我需要将其更改为“ Back”,实际上,“ Back”是一个更好的词来描述其行为。

我正在以这种方式介绍控制器:

let customerContext = STPCustomerContext(keyProvider: StripeClient.shared)
let paymentMethodsViewController = STPPaymentMethodsViewController(configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default(), customerContext: customerContext, delegate: self as STPPaymentMethodsViewControllerDelegate)
let navigationController = UINavigationController(rootViewController: paymentMethodsViewController)
present(navigationController, animated: true)

2 个答案:

答案 0 :(得分:1)

在条带文件中转到STPCoreViewController.m。

只需替换此方法

- (void)commonInitWithTheme:(STPTheme *)theme {
_theme = theme;

if (![self useSystemBackButton]) {
    self.cancelItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                                                    target:self
                                                                    action:@selector(handleCancelTapped:)];

    self.stp_navigationItemProxy.leftBarButtonItem = self.cancelItem;
    }
}

使用

- (void)commonInitWithTheme:(STPTheme *)theme {
_theme = theme;

if (![self useSystemBackButton]) {

    self.cancelItem = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back"
                                   style: UIBarButtonItemStylePlain
                                   target:self
                                   action:@selector(handleCancelTapped:)];

    self.stp_navigationItemProxy.leftBarButtonItem = self.cancelItem;
    }
}

答案 1 :(得分:0)

override func pushViewController(_ viewController: UIViewController, animated: Bool) {
    // first
    let backItem = UIBarButtonItem()
    backItem.title = "Back"
    self.viewControllers.last?.navigationItem.backBarButtonItem = backItem
    // then
    super.pushViewController(viewController, animated: animated)

}