我从数组中创建了几个标签。在某些步骤中,我必须更改标签的x和y坐标,但不知道如何处理标签:

for zone in zoneArray {

        let zoneLabel = UILabel(frame: CGRect(x: locationX, y: locationY, width: 150, height: 75))

        zoneLabel.backgroundColor = UIColor.lightGray
        zoneLabel.layer.masksToBounds = true
        zoneLabel.layer.cornerRadius = 10
        zoneLabel.text = zone}

如果有人可以帮助我,我将非常高兴。

最佳答案

也许您可以在每个标签上添加标签,然后使用标签本身找到所需的标签...

var i = 1
for zone in zoneArray {
    let zoneLabel = UILabel(frame: CGRect(x: locationX, y: locationY, width: 150, height: 75))
    let zoneLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 75))
    zoneLabel.backgroundColor = UIColor.lightGray
    zoneLabel.layer.masksToBounds = true
    zoneLabel.layer.cornerRadius = 10
    zoneLabel.text = zone
    zoneLabel.tag = i
    i += 1
}

07-28 03:44