I\'m currently developing an App for Xamarin Ios and i\'m struggling to find a way to apply a rounded border to simply one side off a button of a UIButton type.
In your UIButton subclass, override the LayoutSubviews
method and add a mask:
public override void LayoutSubviews()
{
var maskingShapeLayer = new CAShapeLayer()
{
Path = UIBezierPath.FromRoundedRect(Bounds, UIRectCorner.BottomLeft | UIRectCorner.TopLeft, new CGSize(20, 20)).CGPath
};
Layer.Mask = maskingShapeLayer;
base.LayoutSubviews();
}
You can do this (IOS 11.0+):
yourLabel.Layer.CornerRadius = 5; // set radius on all corners
yourLabel.ClipsToBounds = true;
yourLabel.Layer.MaskedCorners = (CoreAnimation.CACornerMask)1; // cast the correct value as CACornerMask enum
As CoreAnimation.CACornerMask is an enum marked as Flags and has only 4 values defined (1,2,4,8), I assumed that you can do bitwise operations there but that didn't work for me... So the only way is to cast it with a correct value like this:
yourLabel.Layer.MaskedCorners = (CoreAnimation.CACornerMask)5; //top & bottom left corners rounded
Pick your value from this list based on which corners do you want to be rounded:
That does the trick...