我正在为Xamarin Ios开发一个应用程序,我正在努力找到一种方法,只需将一个圆形边框应用于UIButton类型的按钮。
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();
}
You can do this (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
As CoreAnimation.CACornerMask is an enum marked as Flags and has only 4 values defined (1,2,4,8), I assumed that you can do bitwise operations there but that didn't work for me... So the only way is to cast it with a correct value like this:
yourLabel.Layer.MaskedCorners = (CoreAnimation.CACornerMask)5; //top & bottom left corners rounded
Pick your value from this list based on which corners do you want to be rounded:
That does the trick...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.