Reputation: 2055
Trying to make auto layout work with the keyboard extension. Initially i thought i will make the buttons programmatically but then i realized its better to do it with a xib because of my requirement and multiple screen sizes.
Please see the screenshot below on the current configuration i have made. Button 2:
Button 1 and issue on the app:
All the constraints configuration looks like this:
All i am trying to do here is to make sure the button fills up the screen width. They can expand in width to match screen sizes and orientations. Somehow i feel that its not able to understand the device width. Do i need to specify something for that?
Thanks
Upvotes: 3
Views: 1133
Reputation: 3278
Ben Flores answer did the trick for me, too, but I had to put my code in viewDidLayoutSubviews
. Otherwise my keyboard would crash and not show up. Swift 3 Version:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let frameSize = self.view.frame.size
self.mainView.frame = CGRect(x: 0, y: 0, width: frameSize.width, height: frameSize.height)
}
Upvotes: 1
Reputation: 66
Make sure to set the UIView's dimensions on viewDidLoad so that it looks like something like this:
self.mainView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
I had the same problem and this did the trick for me. Your constraints are just fine.
Upvotes: 5
Reputation: 346
You do not have a constraint on the distance between the two buttons. Try adding on constraint between the buttons for each button.
Upvotes: 1