简体   繁体   中英

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?

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.

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).

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM