---
title: "#251: Face Aware Image Views with AspectFillFaceAware 👤"
url: https://littlebitesofcocoa.com/251-face-aware-image-views-with-aspectfillfaceaware
author: Jake Marsh
date: 2016-08-04
published: 2016-08-04
topics: ["Libraries","UIKit","Images"]
description: "When using UIImageViews, sometimes the built-in content modes can cramp our style. Many times, we're displaying photos of people."
---

# #251: Face Aware Image Views with AspectFillFaceAware 👤

By Jake Marsh, August 4, 2016. HTML: https://littlebitesofcocoa.com/251-face-aware-image-views-with-aspectfillfaceaware

When using **UIImageViews**, sometimes the built-in **content modes** can cramp our style.

Many times, we're displaying photos of people. In these cases, it'd be great if the **image view** could somehow be told to intelligently crop the photo around the person's face.

Today we'll check out a library from [Beau Nouvelle](https://github.com/BeauNouvelle) called [AspectFillFaceAware](https://github.com/BeauNouvelle/AspectFillFaceAware). It's super simple, let's take a look.

[AspectFillFaceAware](https://github.com/BeauNouvelle/AspectFillFaceAware) is essentially just an extension on **UIImageView**. It provides two ways to configure an image view to be <i>"face aware"</i>.

The first is in **Interface Builder**, we can enable the feature by flipping on the feature in the **Inspector**. (Not seeing the option? Run your **project** once, then it should appear).

<img src='https://media.littlebitesofcocoa.com/bite-assets/251-1.png' style='max-width: 260px;' />

Here's the how it looks:

<img src='https://media.littlebitesofcocoa.com/bite-assets/251-2.png' style='max-width: 278px;' />

We can also enable the functionality in code by setting the **image view's** **image** using this new **function**:

``` swift
imageView.set(image: avatar, focusOnFaces: true)
```

We can even throw a quick **corner radius** on the **image view's** **layer** to try out the <i>"face aware"</i> functionality on a circular **view**. (i.e. user avatars):

``` swift
let radius = imageView.bounds.size.width / 2.0
imageView.layer.cornerRadius = radius
```

<img src='https://media.littlebitesofcocoa.com/bite-assets/251-3.png' style='max-width: 278px;' />

Under the hood, the library is using a low accuracy **CIDetector** with a type of `CIDetectorTypeFace` to handle the actual face detection. Want to dive deeper here? We covered **CIDetectors** way back in [Bite #87](https://littlebitesofcocoa.com/87).

More info about _AsyncFillFaceAware_ can be found at [git.io/faceaware](https://git.io/faceaware)
