iOS Xamarin Native 中的圆角按钮

Round Corner Button in Xamarin Native for iOS

我怎样才能在 Xamarin 中有一个像附加图片这样的按钮 iOS? 内容宽度可能因文本长度而异。

每个 UIView 都有一个 CALayer,您可以使用 Layer 属性.

检索它

CALayer 包含制作具有特定 CornerRadiusBorderWidthBorderColor 按钮所需的所有内容:

var button = new UIButton();
button.SetTitle("Hello", UIControlState.Normal);
button.Layer.CornerRadius = 5f;
button.Layer.BorderWidth = 2f;
button.Layer.BorderColor = UIColor.Green.CGColor;