now ,i can use camera for input, but ,maybe user want to use some photo for keyboard input.
why can't i open photo library when i open camera.
class ViewController: UIViewController {
@IBOutlet weak var contentLabel: UILabel!
@IBOutlet weak var inputTextField: UITextField!
@IBOutlet weak var cameraButtonView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let textFromCamera = UIAction.captureTextFromCamera(responder: contentLabel, identifier: nil)
let cameraButton = UIButton(primaryAction: textFromCamera)
cameraButton.frame = cameraButtonView.bounds
cameraButton.setTitle("", for: .normal)
cameraButton.setImage(.init(systemName: "camera.fill"), for: .normal)
cameraButtonView.addSubview(cameraButton)
}
}
extension UILabel: UIKeyInput {
public var hasText: Bool {
text != nil && text!.count > 0
}
public func insertText(_ text: String) {
self.text = text
}
public func deleteBackward() { }
}
Post
Replies
Boosts
Views
Activity
How to dynamically change the height of the section or group when i use UICollectionViewCompositionalLayout.
For example, i want to change the first section's height when i scroll the collectionview up.
I can use the following code to achieve, but this looks very bad.
// in didScroll callback
collectionView.setCollectionViewLayout(currentCollectionViewLayout(), animated: true)