1

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

enter image description here

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?

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Yuki Tanaka
  • 215
  • 2
  • 9

1 Answers1

3

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"}))
Josh Homann
  • 15,933
  • 3
  • 30
  • 33
  • That’s fair enough, and thanks for your answer. Unless an official release from apple for the customizations, its better not to do with hacking way. The alternative solution might be to use other library like WeScan. – Yuki Tanaka Jan 06 '20 at 22:21