ios - 如何让 UIButton 变成一个圆圈?

标签 ios swift uiimageview uibutton

我一直在努力使单元格中的 UIButton 成为一个完美的圆形。不幸的是,圆圈是基于背景图像而不是 UIButton 框架形成的。

我创建一个圆的代码:

cell.StoryViewButton.setImage(image, forState: .Normal)
cell.StoryViewButton.frame = CGRectMake(50, 8, 100, 100)
cell.StoryViewButton.layer.masksToBounds = false
cell.StoryViewButton.layer.cornerRadius = cell.StoryViewButton.frame.width/2
cell.StoryViewButton.clipsToBounds = true

输出如下所示:Output Images for each cell

我怎样才能得到我想要的完美圆形按钮框架?

最佳答案

尝试这样的事情

 cell.StoryViewButton.layer.masksToBounds = true
 cell.StoryViewButton.layer.cornerRadius = cell.StoryViewButton.frame.width/2

如果你需要创建一个视野圈,你必须将 masksToBounds 设置为 true,不要设置 clipsToBounds

希望对您有所帮助。

关于ios - 如何让 UIButton 变成一个圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770456/

相关文章:

swift - LaTeX for Swift 中的代码高亮显示

ios - 通过单元格中的按钮通过 segue 传递数据……不工作……

ios - 从左边缘滑动以关闭 UIViewController

objective-c - UIScrollView subview 中的 UITapGestureRecognizer

json - 需要帮助在 SWIFT 中解析 wikipedia json api

ios - 为什么我的 iOS 应用程序启动屏幕在加载时消失然后又重新出现?

ios - 基于体积的 physicsBody 被手动移动而不接触基于边缘的 physicsBody

具有动态标签高度的 IOS Tableview 自定义单元格

ios - 如何在iOS中拖动图像时将图像重叠在另一个图像上?

ios - 跨设备建立同步音乐流