Published in


Make a single edge rounded! “cornerRadius”


When you are working on the project, you’ll probably deal with lots of shapes that are rounded. To apply, you’ll need to use “cornerRadius” to make the shape rounded.

Sources: EverydayToDo app


The radius to use when drawing rounded corners for the layer’s background.

var cornerRadius: CGFloat { get set }

To make the UIView, UIButton, UIImage.. etc rounded, it’s simply a single line of code as below.

view.layer.cornerRadius = 20

By default, the corner radius does not apply to the image in the layer’s contents property. it applies only to the background color and border of the layer. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners.

When you wanna make a perfect circular shape, then you’ll need to always divide it into 2 of its own width or height. you can always access the width as frame.width .

view.layer.cornerRadius = view.frame.width/2


var maskedCorners: CACornerMask { get set }

Okay, what about how to make the specific edge to be rounded?

sources: GrabMe app

You just need to know the position of the edges.

So to make the top left and bottom left edges rounded, simply type below.

cellView.clipsToBounds = true
cellView.layer.cornerRadius = 20
cellView.layer.maskedCorners = CACornerMask(arrayLiteral: .layerMinXMinYCorner,.layerMinXMaxYCorner)

Make it as an Extension!

you can make extensions to reuse the func everywhere to make it easy to access and keep your code clean!

This is how you’ll use the extension in your ViewController

🔴MaskedCorners [specific edges]

locaionImage.makeCornerRounded(cornerRadius: 20, maskedCorners: [.layerMinXMinYCorner, .layerMaxXMinYCorner])

🔴CornerRadius [entire edges (?)]

locationImage.setCornerRadius(radius: 20)




Daily study logs about iOS development will be updated. Any recommendations or discussions are always welcome

Recommended from Medium

Build A Rich Text Editor App For Mac Using Xcode

Why do I start my Swift learning adventure ?

How to authenticate a user with“Sign in with Apple” and Firebase using a custom token

can’t get enough of imac screen removing. one with a psu other a random restart problem.

can’t get enough of imac screen removing. one with a psu other a random restart problem.

Xcode: 8 SwiftUI Keyboard Shortcuts That Will Make You Even Faster

Laptop keyboard

FriendSurround: Know When Your Friends are Nearby

How to spy on your iOS users by using the Camera

How to get started with iOS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Hey! I am currently studying iOS by myself, and wanna be a cool app developer 🕶 please correct me if i’m wrong or if there’s any thing that you wanna share😊✌️

More from Medium

Creating your own CocoaPod library

Dynamically Change the iOS App Icon in Xamarin.Forms

You put a constraint on core data and your app bricked?

How to Create A Basic API Call in SwiftUI ?