uitraitcollection

IBDesignables and traitCollection in live rendering

有些话、适合烂在心里 提交于 2019-12-31 00:57:25
问题 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 setupForTraitCollection() { switch(traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) { case (.Regular, _): // iPad - not compressed design compressed = false default: // iPhone - compressed design compressed = true } } This code works great when

hasDifferentColorAppearance is true when app is backgrounded

夙愿已清 提交于 2019-12-31 00:45:51
问题 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(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) if #available(iOS 13.0, *) { let hasUserInterfaceStyleChanged = previousTraitCollection?.hasDifferentColorAppearance(comparedTo: traitCollection) ?? false if

UIViewController selective Autorotation with Size classes

蓝咒 提交于 2019-12-25 00:05:26
问题 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 settings (achieved via supportedInterfaceOrientations ). For this example, we assume it is locked to landscape, VC 2 supports both landscape & portrait I use Size classes and in View Controller 1, I check for statusBarOrientation in viewWillTransition

UITraitCollection Class for Updating the Size Class

此生再无相见时 提交于 2019-12-12 05:36:59
问题 Shall i use UITraitCollection Class for Updating the Size Class constraints? Is this Best Practice to update the Constraints? I have gone through the UITraitCollection, but don't know how to differentiate portrait and Landscape? 回答1: It sounds like you want a different layout based on iPad orientation. If adjusting constraint values is all you need to do, you can check the UITraitCollection 's horizontalSizeClass and verticalSizeClass properties. The size class properties values can be found

traitCollection.horizontalSizeClass reports Compact on iOS 8.1, Regular on iOS 8.4 and 9.x

為{幸葍}努か 提交于 2019-12-12 04:31:55
问题 I am adding a Done button in the code to the Navigation Bar for a UIViewController subclass for iPad only, more precisely for Regular Size Class with the below code. We support iOS 8+. The if statement returns Compact Size Class when run on iPad Air 2 with iOS 8.1, and it correctly reports Regular for iOS 8.4 or iOS 9. Is this a bug in iOS, or am I doing something wrong? /// Add 'Done' button for iPad/Regular Size Class private func addDoneButtonIfNeeded() { if traitCollection

Evaluating UITraitCollection's hasDifferentColorAppearance(comparedTo:) result

[亡魂溺海] 提交于 2019-12-11 03:35:45
问题 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 and current trait collection using hasDifferentColorAppearance(comparedTo:) . Documentation says: Use this method to determine whether changing the traits of the current environment would also change the colors in your interface. For example,

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

会有一股神秘感。 提交于 2019-12-09 00:01:39
问题 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 control's background: class MyControl: UIControl { override init(frame: CGRect) { super.init(frame: frame) setup() } required init?(coder: NSCoder) { super.init(coder: coder) setup() } private func setup() { backgroundColor = .myControlBackground } // Lots of code

what are the size classes for the new iPhone X models?

☆樱花仙子☆ 提交于 2019-12-06 13:52:02
问题 Apple has introduced three new iPhone X models: the iPhone XR, XS, and XS Max. What are their size classes, and how do these compare to other iPhone models? 回答1: I'll give three pieces of information for each model: the size classes when in portrait, the size classes when in landscape, and the screen resolution. ↔︎ means horizontal (width) size class ↕︎ means vertical (height) size class The good old-fashioned standard is something like the iPhone 6s: iPhone 6s: ↔︎ compact, ↕︎ regular; ↔︎

what are the size classes for the new iPhone X models?

不羁岁月 提交于 2019-12-04 19:11:24
Apple has introduced three new iPhone X models: the iPhone XR, XS, and XS Max. What are their size classes, and how do these compare to other iPhone models? I'll give three pieces of information for each model: the size classes when in portrait, the size classes when in landscape, and the screen resolution. ↔︎ means horizontal (width) size class ↕︎ means vertical (height) size class The good old-fashioned standard is something like the iPhone 6s: iPhone 6s: ↔︎ compact, ↕︎ regular; ↔︎ compact, ↕︎ compact; 2.0 The three models with Plus in their name, however, when in landscape, are regular,

hasDifferentColorAppearance is true when app is backgrounded

末鹿安然 提交于 2019-12-01 23:43:14
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(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) if #available(iOS 13.0, *) { let hasUserInterfaceStyleChanged = previousTraitCollection?.hasDifferentColorAppearance(comparedTo: traitCollection) ?? false if (hasUserInterfaceStyleChanged) { //Update UI } } } I use this to update the UI, clear some caches etc