首页 > 解决方案 > 如何在 swift 4.2 中将 UIView 变成圆形?

问题描述

UIView 的 width(40) 和 height(40) 相等。

我已经尝试过这些,但它们对我不起作用:

countView?.clipsToBounds = true
self.countView?.layer.cornerRadius = min((countView?.frame.size.width)!, (countView?.frame.size.height)!)/2

并且

self.countView.layer.cornerRadius = (countView.frame.size.width)/2

谢谢

标签: iosswift

解决方案


除了@Stephan 的回答。

用更少的代码:

self.countView.layer.cornerRadius = self.countView.bounds.height / 2

结果:

图像


推荐阅读