Make rounding specific corners easier with extension

Renaming constants goes a long way...

Published: Dec. 13, 2021
Check it out

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.

Filip Němeček profile photo

WRITTEN BY

Filip Němeček @nemecek_f

iOS blogger and developer with interest in Python/Django. Want to see most recent projects? 👀

iOS blogger and developer with interest in Python/Django. Want to see most recent projects? 👀