Mit*_*ens 2 uibutton xamarin.ios ios xamarin
我正在为Xamarin Ios开发一个应用程序,我正在努力找到一种方法,只需将一个圆形边框应用于UIButton类型的按钮.
在您的UIButton子类中,重写该LayoutSubviews方法并添加一个掩码:
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();
}
Run Code Online (Sandbox Code Playgroud)
您可以执行以下操作(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
Run Code Online (Sandbox Code Playgroud)
由于CoreAnimation.CACornerMask是一个标记为Flags的枚举,并且仅定义了4个值(1,2,4,8),因此我假设您可以在那里进行按位运算,但对我不起作用...所以唯一的方法是使用如下正确的值进行转换:
yourLabel.Layer.MaskedCorners = (CoreAnimation.CACornerMask)5; //top & bottom left corners rounded
Run Code Online (Sandbox Code Playgroud)
根据要舍入的角从此列表中选择值:
这样就可以了...
| 归档时间: |
|
| 查看次数: |
1303 次 |
| 最近记录: |