i want to align a picker view (pick) in centre of superview(i.e self.view) in all screen sizes.(iphone-4-5-6-6+,ipad-min-air-pro).
i have aligned it in centre in iphone6 using this code
pick.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(<=112)-[pick(150)]-(<=112)-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(pick)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(<=258)-[pick(150)]-(<=258)-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(pick)]];
General calculation i did is:-
- Subtract half width/height of subview to half width/height of superview.
How to align this view for every screen size without using #define width and height of screen. Also what calculation you did to obtain the result? Also i would appreciate if the constraints are set using visual format language. It should have same alignment for all iOS device screen's. Thank You..