ios - 自定义 iOS UIButton 形状

标签 ios xamarin uibutton

我正在尝试根据线框创建一个半圆形按钮。

但结果不对。

这是我用 C# 编写的代码:

PORCalculatorButton.Layer.CornerRadius = PORCalculatorButton.Layer.Bounds.Width / 2;
PORCalculatorButton.ClipsToBounds = true;
PORCalculatorButton.Layer.MaskedCorners = (CoreAnimation.CACornerMask)3;

按钮也有布局限制。

谁能告诉我哪里做错了或者是否有更好的方法? 我会接受 ObjC、Swift 或 C# 中的任何答案 谢谢。

最佳答案

试试下面的代码:

let circlePath = UIBezierPath.init(arcCenter: 
CGPointMake(PORCalculatorButton.bounds.size.width / 2, PORCalculatorButton.bounds.size.height), radius: PORCalculatorButton.bounds.size.height, startAngle: 0.0, endAngle: CGFloat(M_PI), clockwise: false)
let circleShape = CAShapeLayer()
circleShape.path = circlePath.CGPath
PORCalculatorButton.layer.mask = circleShape

关于ios - 自定义 iOS UIButton 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52423282/

相关文章:

iphone - 分组 TableView 下的 UIButton

ios - UIButton 图像在 tableviewcell 中被扭曲

ios - 向父对象窗体弹出消息发送消息

ios - 使用 KIF 设置应用程序环境

ios - 将 UITableView 的标题更改为 iOS 中的单元格名称

xamarin - 如何在 Xamarin Forms 中创建阴影

c# - 在 Xamarin Forms 中找不到具有正确签名类型的方法

ios - “(_, _, _) -> Void”无法转换为 'Result<Post> -> Void'

ios - 目标覆盖 `OTHER_SWIFT_FLAGS` build设置

sqlite - Xamarin Android - 在哪里存储本地数据库以便我可以查看它