How to make the corners of a button round in iOS?


You might come across a scenarios where you received a UI where the buttons are rounded, and you might wonder how to do that? So here we will see how to make corners of a button round.

We will be seeing both the ways to make the button rounded, one using Storyboard and another programmatically.

Let’s get started! First we will make the corners of button rounded using Storyboard.

Step 1 − Open Xcode → New Projecr → Single View Application → Let’s name it “RoundedButton”

Step 2 − Open Main.storyboard and add a button as show below

Step 3 − Now select the button and tap on Utility area and update the User Defined Runtime Attributes to below value.

Now this value you can modify i.e increase or decrease based on requirement.

In the second method we are going to make the corner rounded Programmatically.

From the Main.storyboard get the @IBOutlet in ViewController.swift and name it “doButtonRounded” and update the same property layer.cornerRadius.

Use the below code for complete reference.

import UIKit
class ViewController: UIViewController {
   @IBOutlet var doButtonRounded: UIButton!
   override func viewDidLoad() {
      super.viewDidLoad()
      doButtonRounded.layer.cornerRadius = 20
   }
}

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements