3

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: enter image description here

Button 1 and issue on the app: enter image description here

All the constraints configuration looks like this: enter image description here

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

KD.
  • 2,015
  • 3
  • 28
  • 59

3 Answers3

5

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.

Ben Flores
  • 66
  • 1
1

You do not have a constraint on the distance between the two buttons. Try adding on constraint between the buttons for each button.

snagra
  • 196
  • 1
  • 5
  • What is the width constraint on Button 1? I see Button 2 has one, but it is currently disabled. – snagra Sep 30 '14 at 00:46
  • There is no width constraint on any of the button as i want them to stretch based on the layout. The ones in grey are deleted already. – KD. Sep 30 '14 at 00:48
1

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)
}
Yannick
  • 3,210
  • 1
  • 21
  • 30