如何在 Swift 的 outlet 集合中将所有标签添加到标签数组的边框?

How to add a border all labels to an array of labels in an outlet collection in Swift?

class ViewController: UIViewController {

    @IBOutlet var labels: [UILabel]!


    override func viewDidLoad() {
        super.viewDidLoad()


        labels[0].layer.borderWidth = 1
        labels[0].layer.borderColor = UIColor.black.cgColor
    }
}

您可以loop通过labels并设置border如下,

labels.forEach { (label) in
    label.layer.borderColor = UIColor.black.cgColor
    label.layer.borderWidth = 1.0
}