Search code examples
user-interfacebuttonxamarinxamarin-studio

Round Corner Button in Xamarin Native for iOS


How can I have a button like attached image in Xamarin iOS? The content width may vary depending on text length.

enter image description here


Solution

  • Every UIView has a CALayer which you can retrieve with the Layer property.

    This CALayer has all the things you need to make a button with a specific CornerRadius, BorderWidth and BorderColor:

    var button = new UIButton();
    button.SetTitle("Hello", UIControlState.Normal);
    button.Layer.CornerRadius = 5f;
    button.Layer.BorderWidth = 2f;
    button.Layer.BorderColor = UIColor.Green.CGColor;