【发布时间】:2017-05-09 16:19:49
【问题描述】:
我目前正在为 Xamarin Ios 开发一个应用程序,我正在努力寻找一种方法来将圆形边框应用到 UIButton 类型按钮的一侧。
【问题讨论】:
标签: ios xamarin xamarin.ios uibutton
我目前正在为 Xamarin Ios 开发一个应用程序,我正在努力寻找一种方法来将圆形边框应用到 UIButton 类型按钮的一侧。
【问题讨论】:
标签: ios xamarin xamarin.ios uibutton
你可以这样做(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
由于 CoreAnimation.CACornerMask 是一个标记为标志的枚举,并且只定义了 4 个值(1、2、4、8),我假设您可以在那里进行按位运算,但这对我不起作用... 因此,唯一的方法是使用这样的正确值进行转换:
yourLabel.Layer.MaskedCorners = (CoreAnimation.CACornerMask)5; //top & bottom left corners rounded
根据您想要圆角的角从该列表中选择您的值:
这就是诀窍......
【讨论】:
在您的 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();
}
【讨论】: