UITraitCollection - allow to access the iOS interface environment by traits such as horizontal and vertical size class, display scale, and user interface idiom
Questions tagged [uitraitcollection]
84 questions
0
votes
1 answer
Swift 5 UICollectionViewCell Autolayout constraints
I am working on remastering Swift and UIKit after a long time.
WorkFlow:
I have created a ViewController with a UICollectionView aligning its centers in both X and Y axis and Proportional Width and Height to Root View.
Assigned to…

Nishanth Vemula
- 336
- 4
- 10
0
votes
1 answer
super initWithFrame returned nil from -traitCollection, which is not allowed
I'm running one of my Objective-C project on XCode 12.0. I have UIControl subclass "SeatingPanelControl" from which another subclass is created named "IpadSeatingPlanControl", wherein I'm getting crash while executing the below code with exception…

iAkshay
- 1,143
- 1
- 13
- 35
0
votes
2 answers
Horizontal size class of popovers in Catalyst?
If I present a view controller as a popover on iPad (by setting its modalPresentationStyle to .popover), it will report its horizontal size class as .compact. But if I run the same code in a Catalyst app, the view controller in the popover reports a…

Tom Hamming
- 10,577
- 11
- 71
- 145
0
votes
1 answer
Is UITraitsCollection the path to having diff iPad Landscape vs Portrait AutoLayout in IB/Storyboard
The Ask:
I want to have different layouts between Portrait vs Landscape on the iPad. (I'm successful on the iPhone But iPad share similar size classes)
What I've done/Tried:
Reading and searching thru Google and SO, I haven't found the solution.…

app4g
- 670
- 4
- 24
0
votes
1 answer
CKBrowseSwitcherViewController override the -traitcollection getter?
2020-11-17 15:56:01.464383-0800 LibraryTally[24499:8154415]
[TraitCollection] Class CKBrowserSwitcherViewController overrides the
-traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate…

HaimingPeng
- 29
- 5
0
votes
1 answer
How can you allow for a user changing to dark or light mode with the app open on iOS?
I have updated views in my app to support dark mode by adding
if #available(iOS 12.0, *) {
if self.traitCollection.userInterfaceStyle == .dark {
//Adapt to dark Bg
} else {
//Adapt to…

eggdeng
- 148
- 9
0
votes
2 answers
Swift: get dynamic float value for dark / light mode
I am using quite often semantic colors in the following way to have dynamic colors for dark mode and light mode. With this approach the colors will also update on runtime when the user switches dark / light mode:
public static var bw100: UIColor =…

Pauli
- 343
- 1
- 4
- 17
0
votes
1 answer
traitCollectionDidChange don't trigger properly in Objective-C
I use traitCollectionDidChange in my swift classes to successfully trigger dark mode changes. Like this:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
toggleDarkMode()
}
Works great. It triggers every…

screenMonkey MonkeyMan
- 393
- 3
- 17
0
votes
2 answers
iOS: After app launched, UIApplication.sharedApplication.keyWindow.rootViewController==nil
I have some code called from my viewWillAppear that relies on the root view controller's traitCollection being valid. To my surprise, even by the time when viewWillAppear is called, UIApplication.sharedApplication.keyWindow.rootViewController is…

eonnu
- 93
- 7
0
votes
1 answer
Test to see if a given iPhone supports a split view in expanded mode
On iPhone 6 (and smaller) the phone never displays a split view in "expanded" mode. That is, the primary and secondary view controllers inside the split view are always shown sequentially. In contrast, on iPhone 6Plus (and larger) the phone will…

Bill Nattaner
- 774
- 7
- 15
0
votes
2 answers
When trait collection changes, constraint conflicts arise as though the stackview axis didn't change
I've a stackview with two controls.
When the UI is not vertically constrained:
Vertical1
When the UI is vertically constrained: Horizontal1
I get both UIs as pictured. There are no constraint conflicts when I show the UIs the first time. …

Dave Largent
- 27
- 11
0
votes
0 answers
UIViewController selective Autorotation with Size classes
The new size classes based Autorotation is a pain if you want custom behavior. Here are my requirements and flow:
View Controller 1(VC1) modally presents View Controller 2 (VC2)
VC1 only supports landscape, portrait, or both depending on user…

Deepak Sharma
- 5,577
- 7
- 55
- 131
0
votes
1 answer
Detect if ViewController presented as FormSheet
I have two ViewControllers.
Presenting
Presented -> can be FullScreen or FormSheet (depending whether it is running on compact or regular horizontal size class)
How can Presented controller detect, whether it is presented as a modal or FormSheet?

Richard Topchii
- 7,075
- 8
- 48
- 115
0
votes
0 answers
How to use a switch statement on something like UITraitEnvironmentLayoutDirection?
I want to find the value of UITraitEnvironmentLayoutDirection. It has the possible values of .leftToRight, .rightToLeft and .unspecified.
How do I use a switch (or some other statement) to detect which of these is the correct value?
I have tried the…
user10474453
0
votes
1 answer
Two UIImagesViews linked to one property for different traits ios
In my storyboard I have one UIImageView for traits RegularRegular and another one for the rest of traits.
This is because they have different layout rules and they have different configuration too.
I want to link them with the viewcontroller, but I…

xarly
- 2,054
- 4
- 24
- 40