UILabel 是圆形的,现在变成了椭圆形

UILabel was circular, now has become eliptical

我在 swift 中使用了以下代码:

label.layer.cornerRadius = CGRectGetWidth(label.frame) / 2
label.layer.masksToBounds = true

这很有效,但后来我把行高调高了,原来是 44,然后我又把它调高了 66。现在圆形标签是椭圆形的。

我注意到,当我将 maskToBounds 设置为 false 时,我可以看到标签的背景更像是一个矩形。它很宽,但没有标签那么高,即使它的尺寸设置为正方形。我做错了什么?

已更新 这是我的限制:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 中,我正在调用一个名为 Configure cell 的函数,该函数采用 UITableViewCell 并仅更新文本。

func configureTextForCell(cell: UITableViewCell, withPlayer player: Player){
    let jerseyLabel = cell.viewWithTag(3000) as! UILabel
        jerseyLabel.text = String(player.jerseyNumber)
    circleLabels(jerseyLabel, hex: "#6470FF")

}

CircleLabels()是这样的:

    func circleLabels(label: UILabel, hex: String){
    label.layer.cornerRadius = label.frame.size.width/2
    label.layer.masksToBounds = true
}

与布置单元格的时间相比,调用时间似乎存在问题。一个简单的解决方法是让故事板和代码中的单元格大小相同

self.tableView.rowHeight 

或者在委托函数中)