【发布时间】:2016-03-09 09:53:00
【问题描述】:
我想在UITableViewCell 中创建一个圆形按钮。
我在 IB 中使用autolayout 约束。
通常,我在viewDidLayoutSubviews 中设置圆角半径,以保持按钮为圆形,尽管autolayout。
我还没有在UITableViewCell 中找到如何做到这一点。我的纽扣是菱形而不是椭圆形的! :-(
谢谢!
这是我制作圆形按钮的方法:
extension UIButton {
func setCircular() {
layer.cornerRadius = layer.frame.width / 2
}
}
我是这样做的
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! MyCellClass
cell.goodButton.setCircular()
}
【问题讨论】:
-
您能告诉我们您的代码吗?
cornerRadius技巧应该可以工作(唯一关心的是性能,因为conrnerRadius不是很快)。 -
将
cornerRadius设置为按钮高度或宽度的一半
标签: ios swift uibutton uitableview