【发布时间】:2015-09-22 16:39:56
【问题描述】:
我试图在运行时在 TableViewCell 的单元格中围绕标签画一个圆圈。
我可以弄清楚如何将它大致围绕标签,但我在将它完全围绕标签居中时遇到了一些麻烦。
圆圈似乎是在标签的右侧和中间绘制。
到目前为止,这是我的代码,我相信这对某人来说很容易。
func drawCircle() {
let x = countLabel.layer.position.x - (countLabel.frame.width)
let y = countLabel.layer.position.y - (countLabel.frame.height / 2)
let circlePath = UIBezierPath(roundedRect: CGRectMake(x, y, countLabel.frame.height, countLabel.frame.height), cornerRadius: countLabel.frame.height / 2).CGPath
let circleShape = CAShapeLayer()
circleShape.path = circlePath
circleShape.lineWidth = 3
circleShape.strokeColor = UIColor.whiteColor().CGColor
circleShape.fillColor = UIColor.clearColor().CGColor
self.layer.addSublayer(circleShape)
}
【问题讨论】:
-
如果你想要动画绘图,你可以使用this answer
-
如果你想要动画绘图,你可以使用this answer