Questions tagged [uitraitcollection]

UITraitCollection - allow to access the iOS interface environment by traits such as horizontal and vertical size class, display scale, and user interface idiom

77 questions
18
votes
4 answers

How do I easily support light and dark mode with a custom color used in my app?

Let's say I have a custom color in my app: extension UIColor { static var myControlBackground: UIColor { return UIColor(red: 0.3, green: 0.4, blue: 0.5, alpha: 1) } } I use this in a custom control (and other places) as the…
rmaddy
  • 298,130
  • 40
  • 468
  • 517
15
votes
3 answers

Adaptive UIPresentationController Based on View Size

I'm moving over to UIPresentationController based presentations for my view controllers but have run into some confusion with the API. I have a custom sidebar style view controller presentation (similar to the LookInside WWDC 2014 demo code). This…
simeon
  • 3,778
  • 2
  • 32
  • 37
9
votes
1 answer

Equivalent of UIApplication.shared.preferredContentSizeCategory in app extension

My open source library needs to be able to call UIApplication.shared.preferredContentSizeCategory. But UIApplication.shared is unavailable in extensions. The build error suggests that I find a view controller-based way to solve my problem, but I'm…
Zev Eisenberg
  • 7,836
  • 5
  • 31
  • 74
7
votes
1 answer

hasDifferentColorAppearance is true when app is backgrounded

Apple recommends that we use traitCollectionDidChange and compare trait collections using hasDifferentColorAppearance to catch when dark mode is toggled, and act on it if we need to. Like this: override func traitCollectionDidChange(_…
andlin
  • 3,534
  • 3
  • 25
  • 43
7
votes
3 answers

How to detect Light\Dark mode change in iOS 13?

Some of the UI setups not working automatically with the Dark/Light mode change as the UIColor. For example shadow in layer. As I need to remove and drop shadow in dark and light mode, I need somewhere to put updateShadowIfNeeded() function. I know…
Mojtaba Hosseini
  • 47,708
  • 12
  • 157
  • 176
6
votes
1 answer

override traitCollection in iOS 13

In my initial view controller, I have have a UITabbarController as a child view controller. I want to have UITabbarController to display its UITabbar with traitCollection having horizontalSizeClass of Compact so that in the tabbar, image and title…
FE_Tech
  • 910
  • 4
  • 19
6
votes
1 answer

UIPresentationController changes size when another view controller is displayed on top of it

I am presenting a modal view controller using UIPresentationController. I am setting the frame of presentedView less than the containView's bounds using following method: override func frameOfPresentedViewInContainerView() -> CGRect { let myDX =…
4
votes
1 answer

app doesn't update and traitCollectionDidChange doesn't fire when user changes appearance in settings

In my app I allow the user to override the appearance that is set on the device. Here's the class that handles updating the UI if they want to override the system-wide appearance: class UserInterfaceStyleController { init() { …
Brian M
  • 3,158
  • 1
  • 9
  • 26
4
votes
0 answers

override UITraitCollection of a UIView

I have a UITabBar which has to have a traitCollection with compact horizontalSizeClass. Because on a regular horizontalSizeClass, UITabBar renders TabBarIcon and Title side by side. I did subclass UITabBar and overriden the traitCollection getter to…
FE_Tech
  • 910
  • 4
  • 19
4
votes
2 answers

iOS13: How to specify color for elevated user interface level in the asset catalog

iOS 13 brings us UIUserInterfaceLevel, which can be either .base or .elevated. The system seems to automatically adjust colors provided to UIView when the elevated level is used in dark mode. However, there seems to be no way how to manually specify…
Tom Kraina
  • 3,159
  • 1
  • 31
  • 53
4
votes
1 answer

IBDesignables and traitCollection in live rendering

I am building my custom UIControl, a custom button built as an IBDesignable, which needs to change based on the size class in which it is being displayed. I have a method -setupForTraitCollection, which looks like this: func…
4
votes
0 answers

Size methods don't get called for detail view controller in UISplitViewController iOS8

I have a UIViewController containing a UICollectionView using a UICollectionViewFlowLayout. The view controller is the detail view controller of a UISplitViewController. The view controller is the flow layout's delegate and the sizes of the…
Avner Barr
  • 13,049
  • 14
  • 82
  • 152
3
votes
1 answer

Evaluating UITraitCollection's hasDifferentColorAppearance(comparedTo:) result

In my app I need to make some custom UI changes when iOS system dark mode settings change. According to https://developer.apple.com/videos/play/wwdc2019/214/ it's explicitly mentioned to implement traitCollectionDidChange and compare the previous…
RTasche
  • 2,503
  • 1
  • 13
  • 15
3
votes
0 answers

How to know centrally when the UI style (dark/light) changes in iOS?

I have an iOS app that had its own theming system (dark/light UI styling) before iOS 13 introduced it natively. This is partly achieved via the UIAppearance methods on various UI elements, like bar button items, segmented controls, and such. To…
Tom Hamming
  • 9,484
  • 9
  • 66
  • 131
3
votes
3 answers

traitCollection.preferredContentSizeCategory.isAccessibilityCategory for iOS 10

The following code works great on iOS11 to detect if the user has set LARGE FONT in their accessibility settings. However, I need to support this in iOS10 as well. How can I accomplish this? Right now the code looks like this: if #available(iOS…
Jeff
  • 1,690
  • 5
  • 29
  • 52
1
2 3 4 5 6