Reputation: 1872
Happy Thanksgiving if you celebrate it!
I have a UIImageView
on storyboard, setup with 4 constraints. The center x constraint has an identifier set (via storyboard), "imageViewTwoCenterX".
I'm trying to find that constraint with the identifier.
PROBLEM: The code below returns 0
for the constraints array count, and never finds the constraint with the identifier.
Am I doing something wrong? Wrong practice? All help is appreciated!
I use this code:
override func viewDidLayoutSubviews() {
print("Constraints Count: \(imageViewTwo.constraints.count)")
for constraint in imageViewTwo.constraints {
if constraint.identifier == "imageViewTwoCenterX" {
print("Found it!")
}
}
}
Upvotes: 0
Views: 82
Reputation: 9311
For constraints other than width/height constraints, IB adds them to the view's superview
. So you won't find them among the image view's constraints. Try listing its superview
's constraints instead.
Upvotes: 1