简体   繁体   English

更改UIImagePickerController中的取消按钮文本

[英]Change cancel button text in UIImagePickerController

I have a problem. 我有个问题。 I want to translate the cancel button in a UIImagePickerController . 我想翻译UIImagePickerController的取消按钮。 I tried different solutions but none of them worked. 我尝试了不同的解决方案,但没有一个起作用。

Please find my actual code that works for changing title text but not for cancel button : 请找到我的实际代码,该代码可用于更改标题文本,但不适用于“取消”按钮:

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 单击此处查看我要更改的内容

Try this, 尝试这个,

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

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

    }

In Info.plist add (or change if already exists) the Localisations property array to the one you need (eg - Spanish or German or anything) 在Info.plist中,将Localisations属性数组添加(或更改,如果已经存在)到您需要的数组(例如,西班牙语或德语或其他任何内容)

If you have set the Cancel button using UIBarButtonItem.SystemItem of cancel (or Interface Builder), it will be localized for you automatically as others have mentioned. 如果您使用cancel (或Interface Builder)的UIBarButtonItem.SystemItem设置了Cancel按钮,它将像其他人一样自动为您本地化。 If you're building the Cancel button yourself for some reason (not needed/recommended if the text is just 'Cancel'), use the appropriate constructor for UIBarButtonItem, for example based on your screenshot: 如果出于某种原因要自行构建“取消”按钮(如果文本仅为“取消”,则不需要/不建议使用),请使用合适的UIBarButtonItem构造函数,例如,基于屏幕截图:

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

If you're not sure how localization works in iOS, please see the Apple Localizing Your App documentation. 如果您不确定本地化在iOS中的工作方式,请参阅Apple 本地化您的App文档。

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

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