简体   繁体   中英

how to add a image to camera overlay view (swift4)

My code right here displays a red line on the top of the imagePicker when taking a photo. I want to do the same thing but add a image in the middle of the red line. See pic. I added the word image in a yellow box as a example of what I am trying to code.

    @IBAction func takePhoto(_ sender: UIButton) {
    imagePicker =  UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    present(imagePicker, animated: true, completion: nil)
    let mainView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height-150))
    let blockView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: 150))
    blockView.backgroundColor = UIColor.red
    mainView.addSubview(blockView)
    imagePicker.cameraOverlayView = mainView
}

在此处输入图片说明

Just do:

let frame             = CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: 150)
let blockView         = UIImageView.init(frame: frame)
blockView.contentMode = .scaleAspectFit
blockView.image       = UIImage(named: "NameOfYourImage")  // Just an example.

See UIImageView .

The frame above needs adjustment of course, to allow for top and bottom margins you show in your screenshot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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