【问题标题】:Change cancel button text in UIImagePickerController更改 UIImagePickerController 中的取消按钮文本
【发布时间】:2018-10-30 09:44:34
【问题描述】:

我有问题。 我想翻译UIImagePickerController 中的取消按钮。 我尝试了不同的解决方案,但都没有奏效。

请找到适用于更改标题文本但不适用于取消按钮的实际代码:

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {    
    imagePicker.navigationBar.topItem?.title = localizedString("ES_CUSTOMERS_EDIT_PHOTOS_TITLE")

    imagePicker.navigationBar.backItem?.title = localizedString("ES_CANCEL_BUTTON")
}

Click here to see What i want to change

【问题讨论】:

标签: ios swift uiimagepickercontroller


【解决方案1】:

试试这个,

    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

         viewController.navigationItem.title = "your text..!!"    

    }

在 Info.plist 中,将 Localisations 属性数组添加(或更改,如果已经存在)到您需要的数组中(例如 - 西班牙语或德语或其他任何内容)

【讨论】:

  • 感谢您的回复。但它只适用于标题,但我想更改取消按钮文本。
【解决方案2】:

如果您使用UIBarButtonItem.SystemItemcancel(或Interface Builder)设置了取消按钮,它会像其他人提到的那样自动为您本地化。如果您出于某种原因自己构建“取消”按钮(如果文本只是“取消”则不需要/不推荐),请为 UIBarButtonItem 使用适当的构造函数,例如根据您的屏幕截图:

navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Cancel", comment: "Cancel the action"), style: .plain, target: <appropriate target here>)

如果您不确定本地化在 iOS 中的工作原理,请参阅 Apple Localizing Your App 文档。

【讨论】:

    猜你喜欢
    • 2022-11-05
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    相关资源
    最近更新 更多