Xamarin Ios - Create rounded buttons on only 1 side

前端 未结 2 455
后悔当初
后悔当初 2021-01-07 05:00

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.

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 05:35

    In your UIButton subclass, override the LayoutSubviews method and add a mask:

    Example: Top and bottom of left side rounded:

    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();
    }
    

提交回复
热议问题