iOS - Find top constraint for a view?

前端 未结 7 1418
情深已故
情深已故 2020-12-28 16:52

I am trying to find the top constraint of the view in code. The top constraint is added in storyboard, and I don\'t want to use an IBOutlet.

Logging the value of the

7条回答
  •  旧时难觅i
    2020-12-28 17:24

    I usually set an identifier of a required constraint in the IB and then find it in the code like this (Swift):

    if let index = constraints.index(where: { $0.identifier == "checkmarkLeftMargin" }) {
        checkmarkImageViewLeftMargin = constraints[index]
    }
    

    OR by @Tim Vermeulen

    checkmarkImageViewLeftMargin = constraints.first { $0.identifier == "checkmarkLeftMargin" }
    

提交回复
热议问题