Using Autolayout in IB how do I position a UIView in the center of the screen programmatically?
autolayout, ios, objective-c
Solution
Use the centerX and centerY constants, and put in a constant of 14 (or -14 not sure which way you want it to be),
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:view attribute:NSLayoutAttributeCenterY multiplier:1 constant:14]];
Problem
I have a UIView that I would like to center horizontally over the main view and then center vertically over the main view, minus about 14 pixels. If I set it up with IB it works on the Retina 3.5, but when running on Retina 4 it is of course off by roughly 40 pixels. I am thinking the best solution is establishing these constraints programmatically based on screen height?