仅在一侧创建圆形按钮

仅在一侧创建圆形按钮

本文介绍了Xamarin Ios - 仅在一侧创建圆形按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 Xamarin Ios 开发一个应用程序,我正在努力寻找一种方法来将圆角边框应用到 UIButton 类型按钮的一侧.

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.

推荐答案

在你的 UIButton 子类中,覆盖 LayoutSubviews 方法并添加一个掩码:

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

这篇关于Xamarin Ios - 仅在一侧创建圆形按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:24
查看更多