Reputation: 4083
Im trying to add the use auto layout feature for the views in my .xib files, the goal is to have the views adjusted according to the correct screen size.
when I add auto layout to a view and set freeform and change the view size to 568 the view looks correctly on the iPhone 5 simulator but when trying to push buttons at the bottom they are not working while if I run the same app on iPhone 4 the view looks correctly and the buttons are working.
What am I missing ? anyone knows about tutorials or where I can find info how to convert regular xibs without autolayout to work ?
Upvotes: 1
Views: 1237
Reputation: 3733
I'm a little late to the party, but I think you have to add constraints to your button besides just adding it into a xib file.
Here's a link to AutoLayout tutorial and/or you can watch a WWDC Sessions will give some insights:
Upvotes: 0
Reputation: 3076
I run into same problem. In my case:
self.view
\- ...
\_self.wrapper
\_self.button
The code not works:
NSDictionary *metrics = @{@"padding":[NSNumber numberWithFloat:kGridPadding]};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[head]-padding-[wrapper]-|" options:0 metrics:metrics views:views]];
The reason is the height of 'wrapper' is 0, although the button is still visiable. So it can be fixed by giving enough width and height like this:
NSDictionary *metrics = @{@"padding":[NSNumber numberWithFloat:kGridPadding],
@"screenHeight":[NSNumber numberWithFloat:self.view.bounds.size.height]};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[head]-padding-[wrapper(screenHeight)]-|" options:0 metrics:metrics views:views]];
--> a better way is make the height of wrapper increase automatically, but I don't know how to do that now?
Upvotes: 0
Reputation: 10294
Chances are your buttons aren't sitting on top of their superviews. You need to have the superview of the buttons constrain to the bottom of the superview.
Unfortunately without seeing anything, its hard to help you any further than that.
Upvotes: 1