Sam Luther
Sam Luther

Reputation: 1190

ios adaptive layout / size classes to target specific phone size?

I've lost what's left of my mind messing with adaptive layout and size classes. Not that I was a genius to begin with, but now I'm bald.

Say I have a very simple layout that I want to make sure looks perfect ( and by perfect I mean all my ui elements are present) on the 3.5, 4, 4.7 and 5.5 iphones.

Ok, I start off in Any Any size, all the elements placed with constraints, no warnings, no errors. Good to go. Load up the various size phones in preview mode, 5.5 looks good, 4.7 looks good, 4 looks ok, 3.5 needs some work.

I want to futz with 3.5 and 4 (NOT 4, 4.7 and 5.5) Are size classes the way to achieve this goal? Would I need to do multiple storyboards or do this or some type of device size checking in code? I came across one guy who went the route of multiple storyboards, seemed like a pretty big hack and a bunch of people were skeptical of his approach but I bet he still has hair.

I guess what I'm asking, can size classes be used to target a specific size? If you want your layouts looking perfect on 3.5, 4, 4.7 and 5.5 what is the suggested way to go about this?

Upvotes: 1

Views: 563

Answers (3)

Rabindra Nath Nandi
Rabindra Nath Nandi

Reputation: 1461

There is only one type of Size-classes named compact size is available for all iPhone Devices with different sizes. So , the solution is 1. When you set constraint u have to set relation (Equal, greater than or equal or less than or equal ). This with help to resize your view or inter-spacing between views according to the size of current devices .

To get your expected look, we have to clear about the different constraint setting with high or low priority , relations , constraint value for different sizes(compact-regular, compact-compact, regular-regular, regular-compact).

Upvotes: 0

Filip Radelic
Filip Radelic

Reputation: 26683

No, size classes can't really help you with that. And please don't do multiple storyboards. It's hard to give some concrete advice without seeing your UI and what problems it has on smaller screens, but in most cases where your UI can't properly scale between sizes within the same size class, I'd say you should probably rethink your UI or your constraints.

In worst acceptable case you could have outlets to constraints that are problematic and update those from code depending on screen size.

Upvotes: 1

Cesare
Cesare

Reputation: 9419

Check out my answer here:

https://stackoverflow.com/a/28093987/1135714

As I said, AutoLayout isn't device-specific, but there's a workaround for that. You can either place a UIView or set constraints via code (which is pretty easy).

Upvotes: 0

Related Questions