ios - 如何快速创建弧形 ios

标签 ios swift uibutton

我有一个带有一些按钮的应用程序。我想创建一个弧形按钮,如下图enter image description here

我该怎么做?我使用以下代码来实现此目的。

button.layer.cornerRadius =  button.bounds.size.height

button.layer.cornerRadius =  0.5*button.bounds.size.height

我也尝试过使用宽度

button.layer.cornerRadius =  button.bounds.size.width

button.layer.cornerRadius =  0.5*button.bounds.size.width

我该怎么做?请有人帮我解决这个问题。

最佳答案

要创建弧形,您需要使用UIBezierPath 请阅读苹果的 UIBezierPath_class文档。

他们提到了创建弧形的方法。

Creates and returns a new UIBezierPath object initialized with an arc of a circle.

enter image description here

用于构建路径

Appends an arc to the receiver’s path.

enter image description here

您也可以引用Core Graphics Tutorial Part 1通过示例并在浏览器上搜索 arc 关键字,您将重定向到页面上的弧形。

关于ios - 如何快速创建弧形 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35011735/

相关文章:

iphone - 自定义 UITableView 不显示

ios - 如何在 Swift 的通知中发送枚举值?

swift - UITableview 中的收藏夹按钮 (Swift 4)

ios - 具有右图像和居中文本的 UIButton

ios - 将类作为参数传递并使用此类实例化对象

ios - 我是否需要在 Thread 中运行 AudioServicesCreateSystemSoundID

iOS Table View,更改表格索引的框架

arrays - 表格 View ,其中包含每个联系人的第一个字母的部分

swift - 如何从顶部而不是从底部添加 NSButtons?

ios - 使用下一个和上一个UIButton切换UITextView/UILabel中的不同文本