gpt4 book ai didi

ios - UITableViewCell 中的圆形按钮

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:36 24 4
gpt4 key购买 nike

我想在 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()
}

最佳答案

我想你忘了在你的类上添加 self.imageView.layer.masksToBounds = true

override func layoutSubviews() {
super.layoutSubviews()

self.makeItCircle()
}

func makeItCircle() {
self.yourbutton.layer.masksToBounds = true
self.yourbutton.layer.cornerRadius = CGFloat(roundf(Float(self.yourbutton.frame.size.width/2.0)))
}

有关更多信息,请参阅 this

关于ios - UITableViewCell 中的圆形按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35888155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com