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

时间:2018-10-09 05:27:35

标签: arrays swift uilabel iboutletcollection

class ViewController: UIViewController {

    @IBOutlet var labels: [UILabel]!


    override func viewDidLoad() {
        super.viewDidLoad()


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

1 个答案:

答案 0 :(得分:2)

您可以looplabels并将border设置如下,

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