Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var imageView: UIImageView?
let marginConstant : CGFloat = 20.0
let button:UIButton = {
let view = UIButton()
view.translatesAutoresizingMaskIntoConstraints = false
let config = UIImage.SymbolConfiguration(pointSize: 50)
view.setImage(UIImage(systemName: "photo.fill", withConfiguration: config), for: .normal)
return view
}()
let visionButton:UIButton = {
let view = UIButton()
view.translatesAutoresizingMaskIntoConstraints = false
let config = UIImage.SymbolConfiguration(pointSize: 50)
view.setImage(UIImage(systemName: "eye.fill", withConfiguration: config), for: .normal)
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setupImageView()
setupImagePickerBtn()
setupVisionButton()
setupCollectionView()
}
func setupImageView(){
imageView = UIImageView(frame: .zero)
imageView?.contentMode = .scaleAspectFit
imageView?.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(imageView!)
NSLayoutConstraint.activate([
imageView!.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: marginConstant*2),
imageView!.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -marginConstant*2),
imageView!.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: marginConstant*2),
imageView!.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -marginConstant*2),
])
}
func setupImagePickerBtn(){
self.view.addSubview(button)
NSLayoutConstraint.activate([
button.heightAnchor.constraint(equalToConstant: 150),
button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -marginConstant),
button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -marginConstant/2),
button.widthAnchor.constraint(equalToConstant: 150)
])
button.addTarget(self, action: #selector(onButtonClick), for: .touchUpInside)
}
func setupVisionButton(){
self.view.addSubview(visionButton)
NSLayoutConstraint.activate([
visionButton.heightAnchor.constraint(equalToConstant: 150),
visionButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: marginConstant),
visionButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -marginConstant/2),
visionButton.widthAnchor.constraint(equalToConstant: 150)
])
visionButton.addTarget(self, action: #selector(startVisionRequest(sender:)), for: .touchUpInside)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment