Search code examples
objective-cswiftcalayerios11

Using CACornerMask with Objective-C


With iOS 11 we now have CACornerMask and the maskedCorners property on CALayers. However I am unable to set multiple corners to be rounded at the same time in Objective-C.

The swift implementation is:

view.layer.cornerRadius = 10
view.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner]

But in Objective-C this does not work:

view.layer.maskedCorners = @[kCALayerMinXMinYCorner, kCALayerMaxXMinYCorner];

I think this is because Swift is using an OptionSetType but I don't know what the Objective-C equivalent to that is.

Has anyone been able to successfully use multiple masked corners with Objective-C? Thanks in advance for your help.


Solution

  • In Objective-C you need to use bitwise OR (|) to combine the values:

    view.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;