---
title: "#211: Rounding Corners with UIRectCorner and UIBezierPath 🖌"
url: https://littlebitesofcocoa.com/211-rounding-corners-with-uirectcorner-and-uibezierpath
author: Jake Marsh
published: 2016-03-14
topics: ["UIKit","Techniques"]
description: "The real world doesn't have straight edges. Things are rounded. Our UIViews can be too! Most of us know about the cornerRadius property on CALayer."
---

# #211: Rounding Corners with UIRectCorner and UIBezierPath 🖌

By Jake Marsh, March 14, 2016. HTML: https://littlebitesofcocoa.com/211-rounding-corners-with-uirectcorner-and-uibezierpath

The real world doesn't have straight edges. Things are rounded. Our **UIViews** can be too! Most of us know about the `cornerRadius` **property** on **CALayer**. We can set a value, then see all the corners round themselves to that value:

``` swift
contentView.layer.cornerRadius = 8
```

<img src='https://media.littlebitesofcocoa.com/bite-assets/211-rounding-corners-with-uirectcorner-and-uibezierpath-1.png' style='max-width: 136px;' />

Nice, but what if we only want to round <i>some</i> of the corners though?

``` swift
let cornerRadius: CGFloat = 8
let maskLayer = CAShapeLayer()
  
maskLayer.path = UIBezierPath(
  roundedRect: view.bounds,
  byRoundingCorners: [.BottomLeft, .BottomRight],
  cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)
).CGPath
  
view.layer.mask = maskLayer
```

For this, we'll need to get a bit more creative. We can use an often-overlooked type called _UIRectCorner_.

It lets us describe which corners we'd like to round. Then we'll use a _UIBezierPath_ to create a "mask" **layer** that will only allow some of the content to "show through".

We pass in an option set for the `byRoundingCorners` **parameter**, listing out the corners we'd like rounded.

<img src='https://media.littlebitesofcocoa.com/bite-assets/211-rounding-corners-with-uirectcorner-and-uibezierpath-2.png' style='max-width: 136px;' />

Success! Happy rounding!

**Update:** Shout-out to [Reddit-reader /u/cuomo456](https://www.reddit.com/r/iOSProgramming/comments/4adg9v/little_bites_of_cocoa_211_rounding_corners_with/d0zhmom) who reminds us to update/replace our layer masks anytime the view/layer we're masking's frame or bounds changes. If we don't, we could find ourselves scratching our heads why our rounded corners aren't working in a **UITableViewCell**, for example.
