UILabel是循环的,现在已成为eliptical

时间:2016-06-28 02:15:37

标签: swift uilabel

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

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

这很好用,但是我的排高度更高,它是44,然后我做了66高。现在圆形标签是椭圆形的。 enter image description here

我注意到,当我maskToBounds为假时,我可以看到标签的背景更像是一个矩形。虽然它的尺寸设置为方形,但它的宽度并不像标签那么高。我做错了什么?

enter image description here

更新 这是我的约束: enter image description here

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
}

1 个答案:

答案 0 :(得分:1)

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

self.tableView.rowHeight 

或在委托函数中)

相关问题