Latest 0.9.1
License MIT
Platforms ios 10.0

A ultra simple camera viewer for UIView



  • Swift 4
  • iOS 10.0+
  • XCode 9+

Using cocoapods:

target 'YouProject' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks

  # Pods for TestCameraPod
  # this is temporary due to cocoapods publish issue.
  pod 'BHPhotoView', :git => ''



1 – Creating Code Base

Add a UIView to your screen:

Adding UIView

Set your uiview class to BHPhotoView:

Set Custom Class

In your ViewController:

Import the lib:

import UIKit
import BHPhotoView //<-- here

class ViewController: UIViewController {


Link a IBOutlet from your UIView:
Linking IBOutlet

2 – Configuring for Camera

In your Info.plist project, set the Privacy - Camera Usage Description with any text you want.

Set Info PList

In your ViewController, add the BHPhotoViewDelegate:

extension ViewController: BHPhotoViewDelegate {
    func onPhotoCaptured(_ view: BHPhotoView, photo: UIImage) {
        // when photo has been taken, this method will be called.

    func onPhotoCapturingError(_ view: BHPhotoView, error: BHPhotoViewError) {
        // if some error occurs, this method has been called.

Set the delegate:

import UIKit
import BHPhotoView

class ViewController: UIViewController  {

    @IBOutlet weak var photoView: BHPhotoView!

    override func viewDidLoad() {
        self.photoView.delegate = self //<-- here

3 – Starting and capturing from camera

To start camera, call the start method:

override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.
    self.photoView.delegate = self

    // cameraPosition can be: .front | .back | .unspecified
    self.photoView.start(cameraPosition: .front)

To capture photo, call the capturePhoto method:

@IBAction func onTouchMyButton(_ sender: Any) {
    // when you call this method and photo has been taken,
    // the delegate methods will be called.

To stop streaming, use the stop method:

@IBAction func onTouchMyButton(_ sender: Any) {

4 – Result =)


Release Notes


  • Feat: adding stop method.


  • Fix: cocoapods validation.

0.9.0: First release o/

Latest podspec

    "name": "BHPhotoView",
    "version": "0.9.1",
    "summary": "A ultra simple UIView for camera capturing.",
    "description": "Using your custom UIView to display camera stream and take a photo from it. Nothing more.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Ben-hur Santos Ott": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.9.1"
    "platforms": {
        "ios": "10.0"
    "source_files": "BHPhotoView/BHPhotoView.swift",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This