Questions tagged [adaptive-layout]

Adaptive Layout is a technique for supporting multiple display sizes and orientations in iOS applications.

Technical Overview

Adaptive Layout has been available since iOS 8. Instead of specific device types, or orientations, it introduces the concept of Size Classes. A size class can be either Compact or Regular in Horizontal or Vertical directions. Additionally there is an Any size class which serves for general layout constraints.

Some examples:

  • Compact Width + Regular Height represents an iPhone in portrait orientation.
  • Any Width + Compact Height will apply to iPhones in landscape.

Each size class may have its custom layout, with its own set of constraints. Adaptive Layout uses a hierarchical approach to determine which rules to use:

  • Any rules are used for general use: If there are no specific rules in either Horizontal or Vertical layouts, the screen will show according to these constraints. This is the perfect place for defining shared layout rules
  • Use Regular or Compact to achieve custom layout rules for a specific subset of Size classes. For example, to achieve a speficic layout for iPhones in landscale mode, proper constraints must be installed in the Any Width + Compact Height size class.

To support this new approach UIKit was also extended with Trait Collections. A UITraitCollection object describes the properties of an user interface element, such as its display scale (Retina or Non-Retina resolutions), device idiom (iPhone or iPad) and its size class.

In case of any change in layout (e.g.: a rotation), developers can examine the new traits, and act accordingly. In order to support this new approach, previous rotation-focused methods have been deprecated in favor of handling transitions between different trait collections.

Where to start?

106 questions
21
votes
4 answers

Frame "will be different at run time".... Isn't that the whole point?

Maybe striving for a "warning free" project is futile, but I am nervous enough about Adaptive Layout/ AutoLayout that I am compelled to try and squash these warnings. I have a uiview that I want to be dynamically sized based on the portrait screen…
Electro-Bunny
  • 1,380
  • 2
  • 12
  • 33
17
votes
3 answers

iOS Prevent timer UILabel 'shaking' when numbers change

I have a UILabel which shows the output of a timer in the format MM:ss:SS (minutes, seconds, centiseconds), however it "shakes" from left to right as the width of the centiseconds changes - "11" is narrower than "33" for example. Is there any way I…
Chris Byatt
  • 3,689
  • 3
  • 34
  • 61
17
votes
8 answers

iOS 8 presentationController determine if really is popover

I'm using the new adaptive "Present As Popover" capability of iOS 8. I wired up a simple segue in the StoryBoard to do the presentation. It works great on an iPhone 6 Plus as it presents the view as a popover and on an iPhone 4s it shows as a full…
Tod Cunningham
  • 3,691
  • 4
  • 30
  • 32
10
votes
2 answers

Adaptive Layout in Xcode 8

I am developing app using Xcode 8 (beta 1). Unfortunately, I am not able to find "Size Classes" option. In Xcode 7, there was option "Use Size Classes". But in Xcode 8 there is no such option. Is there any help for using Size Classes or similar in…
Khawar
  • 9,151
  • 9
  • 46
  • 67
9
votes
5 answers

iOS Autolayout adaptive UI problems

I want to change my layout depending on if the width is greater than the height. But I keep getting layout warnings. I watch both WWDC videos on adaptive layout which helped a lot but did not solve the problem. I've created a simple version of my…
Haagenti
  • 7,974
  • 5
  • 38
  • 52
8
votes
2 answers

How can I create a segue that will use a popover on iPad, and push onto the navigation stack on the iPhone?

In my app, there are certain view controllers where on iPad (or to be more specific, a regular horizontal size class) it makes sense to present them as popovers, but on iPhone (or a compact horizontal size class) it makes sense to push them onto the…
Chris Vasselli
  • 13,064
  • 4
  • 46
  • 49
7
votes
1 answer

How to structure css using BEM methodology for adaptive web pages?

It is easy to use BEM for fixed layouts. What is about css styles structure for adaptive web pages with media queries? html sample:
pepeevich
  • 183
  • 1
  • 4
  • 20
7
votes
2 answers

iOS 8 - Find constraints for a UIView with identifier

I am trying to change a constraint for an ImageView for iPhone 4S,5,5S in viewDidLoad: for (NSLayoutConstraint *constraint in logoImage.constraints) { if ([constraint.identifier isEqualToString:@"logoTopIdentifier"]) { …
BlackM
  • 3,927
  • 8
  • 39
  • 69
7
votes
2 answers

iOS 7 Auto Layout vs. iOS 8 Adaptive Layout, is there a difference?

Is there a difference between iOS 7 Auto Layout and iOS 8 Adaptive Layout? Or is it just -the adaptive layout- a more enhanced version with more features to help building more flexible layouts that fit different screen sizes? I really can't figure…
Abdurrahman
  • 6,306
  • 3
  • 19
  • 20
6
votes
0 answers

IOS / Swift - How to adjust font size and margin size for each devices screen sizes with autolayout

Coming from the Android world, I'm trying to create my first IOS app in swift. Actually stuck to build interfaces that are adpative to all screen sizes from Iphone 5s to Ipad 12.9". Autolayout works well except that I can't find how to easily…
Abel Hamilton
  • 73
  • 1
  • 6
6
votes
1 answer

Static cell has background color on iPhone, but not on iPad - can not find the reason

In an iOS 8 project with storyboard and adaptive layout (aka size classes) I use static cells in 2 scenes - And for some reason the blueish background color of the top cell is not shown on iPad: Please, what could be the reason for that? I've even…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
5
votes
2 answers

Set font size using size classes programmatically

There are a few posts on this, but none seem to have a complete solution. Using adaptive layout via IB I can easily change font sizes for specific size classes, however I have a custom view using UILabels and I want to programmatically set the font…
MikeJ
  • 2,367
  • 3
  • 18
  • 23
4
votes
1 answer

Changing Size Classes

I’ve been trying to get up and running with building adaptive layouts in pure code (no storyboards used). I use layout anchors to set constraints and utilize traitCollectionDidChange method to vary between various sets of constraints and other…
Andrei
  • 71
  • 1
  • 6
4
votes
1 answer

Changing constraint multiplier using traits

I have several objects with a width of at least 75% of the screen width. The issue is that they do not look as good on iPads or landscape mode. I want to change the "75%" for different traits but couldn't figure out how. I've looked at the details…
Nimrod Shai
  • 1,149
  • 13
  • 26
4
votes
1 answer

CSS @media-like rules for formatting of a DIV content

I need CSS rules which can dynamically adapt/re-format a content of a div to any changes of the size (even if the JavaScript is disabled). Is it possible? Like: @media (min-width:600px ) { div .content { column-count: 2; }} @media (min-width:900px )…
hupapayo
  • 41
  • 1
1
2 3 4 5 6 7 8