Chapter 13. Custom Views and View Controllers

Selfiegram is now themed and looking much nicer than before, but we still haven’t really done much customization beyond some color tweaks and font changes. Let’s take a look at building a custom UIView and UIViewController subclass to further improve our app.

The reason to make a custom view or view controller is to do something that isn’t available in the ones Apple or third-party libraries provide. In our case we are going to be making a replacement for the image picker we are currently using to take photos.

Note

There are reams of third-party camera view controllers out there, each with its own strengths and weaknesses, but we are going to be creating our own. This is both because it is a good example of what it involves and because it lets us talk a bit about working with the camera in iOS, beyond what we could do with the image picker.

We will be using the AVKit framework to handle the communication with, and presentation of, the camera. AVKit is a framework that includes a great deal of classes and functions for interacting with, displaying, and creating audio and video content—hence the name AVKit. Using AVKit you could build yourself an entire video and audio editing suite, but we’re going to start small and just capture images from the camera.

There is a lot to do to this chapter. We will need a custom view to show what the camera is seeing, we are going to need a custom view controller to perform the role of talking ...

Get Learning Swift, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.