更改VNdocumentCameraViewController的措辞

huangapple go评论88阅读模式
英文:

Change the wording of VNdocumentCameraViewController

问题

我想通过显示VNDocumentCameraViewController来更新视图中显示的文字。
例如,

更改VNdocumentCameraViewController的措辞

在这张图片中,我想要更改:

  1. Position the document in view -> 将文档定位在视图中 -> 你好,世界

  2. Cancel -> 取消 -> 停止

  3. Auto -> 自动 -> 删除按钮

我不确定VNDocumentCameraViewController具有哪些属性,因此无法在子类中覆盖这些按钮标题的值。
如何覆盖这些按钮标题为不同的值呢?

英文:

I'd like to update the wordings shown in the view by presenting the VNDocumentCameraViewController.
For example,

更改VNdocumentCameraViewController的措辞

In this picture, I'd like to change,

  1. Position the document in view -> Hello world

  2. Cancel -> Stop

  3. Auto -> Delete the button

I'm not sure what attributes VNDocumentCameraViewController has, so cannot override the values in the child class.
How is it possible to override these button title to a different value?

答案1

得分: 3

以下是翻译好的内容:

简短回答是,如果你要发布到应用商店,是不允许这样做的;Apple提供了UI,而且因为他们没有提供自定义的方法,你应该将它保持原样。更详细的回答是,你可以遍历视图层次结构,找出哪些标签包含哪些文本,然后可以简单地更改这些UILabel上的文本。有很多原因不建议这样做:

  1. 这可能会导致你的应用被应用商店拒绝。
  2. 实现可能会在不同版本之间发生变化,破坏你的应用程序。
  3. 文本是本地化的,因此你的更改在其他语言中不起作用。

在提醒之后,以下是用于执行深度优先搜索以查找与特定条件匹配的视图的代码,例如,是否为带有特定文本的UILabel。

import SwiftUI
import PlaygroundSupport

let a = UIView()
let b = UIView()
let c = UIView()
let l = UILabel()
let z = UILabel()

a.addSubview(b)
a.addSubview(c)
b.addSubview(z)
c.addSubview(l)
l.text = "hello"

extension UIView {
  func child(matching predicate: (UIView) throws -> Bool) rethrows -> UIView? {
    for child in subviews {
      if try predicate(child) {
        return child
      }
      if let found = try child.child(matching: predicate) {
        return found
      }
    }
    return nil
  }
}

print(l === a.child(matching: {($0 as? UILabel)?.text == "hello"}))

希望这对你有所帮助。

英文:

The short answer is that you are not allowed to do this if you re releasing to the App Store; Apple provides the UI and since they don't provide a way to customize it you are supposed to leave it as is. The longer answer is that you can walk the view hierarchy and figure out which labels contain which text and then you can simply change the text on these UILabels. Its bad to do this for a lot of reasons:

  1. It can get you rejected from the app store
  2. The implementation can change between version, breaking your app
  3. The text is localized so your changes will not work in other languages

With that warning, here is code to do a DFS search to find a view that matches a certain predicate, for instance, being a UILabel will some specific text.

import SwiftUI
import PlaygroundSupport

let a = UIView()
let b = UIView()
let c = UIView()
let l = UILabel()
let z = UILabel()

a.addSubview(b)
a.addSubview(c)
b.addSubview(z)
c.addSubview(l)
l.text = "hello"

extension UIView {
  func child(matching predicate: (UIView) throws -> Bool) rethrows -> UIView? {
    for child in subviews {
      if try predicate(child) {
        return child
      }
      if let found = try child.child(matching: predicate) {
        return found
      }
    }
    return nil
  }
}

print(l === a.child(matching: {($0 as? UILabel)?.text == "hello"}))

huangapple
  • 本文由 发表于 2020年1月7日 00:04:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615267.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定