How to create top and bottom rounded corners for UIView with Swift

By default if you set the corner radius on a views layer it will apply that radius to all the corners. If you only want some of the corners to have the radius applied, you will need to use maskedCorners.

In this quick tutorial I will show you how to use maskedCorners so that you can apply corner radius to specific corners of your view.

Below is the extension that I created:

Once you add that to your project all you need to do is the following in order to apply the corner radius to the corners you choose:

There are five options that you can pass through to the usingCorners argument. They are:


I hope that helped.

Some of my other articles:

How to blur and image using CIFilter with Swift:

How to read a barcode or QRCode with Swift:

How to use SKStoreReviewController with Swift:

Getting Started with Realm Database with Swift: