Make rounding specific corners easier with extension

Renaming constants goes a long way...

Published: Dec. 13, 2021
I want a Press Kit

I was tired spending time to distinguish between .layerMinXMaxYCorner and .layerMinXMinYCorner when trying to round only specific corners with the maskedCorners property on CALayer.

So I created simple extension to make this much more pleasant. (At least for me 😃).

import UIKit

extension CACornerMask {
    static let bottomLeft = CACornerMask.layerMinXMaxYCorner
    static let bottomRight = CACornerMask.layerMaxXMaxYCorner
    static let topLeft = CACornerMask.layerMinXMinYCorner
    static let topRight = CACornerMask.layerMaxXMinYCorner
}

And then usage:

view.layer.maskedCorners = [.bottomLeft, .bottomRight]

Much more comprehensive to my brain.

Keep in mind, that this is for iOS. On macOS you'll need to modify the definitions, because the Y axis is flipped.

Bluesky logo

Follow on Bluesky to not miss new posts

Filip Němeček profile photo

WRITTEN BY

Filip Němeček Mastodon

iOS blogger and developer with interest in Python/Django.

iOS blogger and developer with interest in Python/Django.