Metro UIButton in iOS - Here's how

IanVinkIanVink CAInsider, University ✭✭✭
edited December 2014 in Xamarin.Forms

Inspired by: http://forums.xamarin.com/discussion/20098/button-renderer-ios

[assembly: ExportRenderer(typeof (CustomImageButton), typeof (CustomImageButtonRenderer))]

namespace Bahai.iOS.Renderers
{
 public class CustomImageButtonRenderer : ButtonRenderer
 {
    private UIButton _btn;

    public CustomImageButtonRenderer()
    {
    }

    public override void Draw(RectangleF rect)
    {
        base.Draw(rect);

        // ADD some gradient effects! (optional)
        //============================
        // CAGradientLayer btnGradient = new CAGradientLayer();
        // btnGradient.Frame = btn.Bounds;
        // btnGradient.Colors = new CGColor[] {Color.White.ToCGColor(), Color.FromHex("#0073BD").ToCGColor()};
        // btn.Layer.InsertSublayer(btnGradient, 0);
        // btn.Layer.MasksToBounds = true;
        // btn.Layer.BorderColor = Color.FromHex("#0073BE").ToCGColor();

        //METRO Effect (Square look)
        _btn.Layer.BorderWidth = 0;
        _btn.Layer.CornerRadius = 0;

        //Change the text color
        //  btn.SetTitleColor(Color.Black.ToUIColor(), UIControlState.Normal);
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement == null)
        {
            _btn = (UIButton) Control;
        }
       }
   }
Sign In or Register to comment.