Reputation: 1592
I'm working on a custom keyboard for iOS 8 and I'm having problems with AutoLayout. My keyboard is a .xib file that contains an UIView, the size of the view is 320x220, this size is great for 3.5 & 4 inch display, but when I want the keys to automatically layout to fit for 4.7 & 5.5 inch displays.
I want the keys to automatically change their width and height and be centred in the view.
Here's how my UIView looks like:
I will appreciate if anyone would guide me how to achieve what I'm looking for with AutoLayout.
Thanks!
Upvotes: 1
Views: 452
Reputation: 1329
There are two possibilities here:
By adjusting the widths of the keys, you can make it so they span all the way across, just like on the smaller screens. To do this, just add a leading and trailing constraint from each key to its previous and next respectively. Also add a leading constraint from the superview to the first key and a trailing constraint from the superview to the last key. Lastly, add an equal width constraint on all the keys to each other.
Another option is to keep the keys the same size, but center them in the view. In order to do this, you will need to create a superview to place all of the keys in (per row) and then put that view inside the keyboard. The row's width should be dynamic (determined by the combined width of its children). Since you will be using constant height and width for the keys, the superview can determine its width. The final step is to horizontally center the key's superview in its container (the keyboard).
Upvotes: 3