214 Implementing Dark Mode On Ios
214 Implementing Dark Mode On Ios
© 2019 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
•
RGB: 0 0 0
systemGroupedBackground
systemBlue
label
systemGroupedBackground
systemBlue
systemBackground
systemBackground
secondarySystemBackground
tertiarySystemBackground
Primary Primary
Secondary Secondary
Tertiary Tertiary
Quaternary Quaternary
Title Title
Subtitle Subtitle
Placeholder Placeholder
Disabled Disabled
Designing for Dark Mode
Color white
Use Dynamic Colors NEW
light white
Color
white
dark black
•
Demo
UIBlurEffect
style = .systemMaterial
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
UIVibrancyEffect
style = .fill
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
UIVibrancyEffect
UIVisualEffectView
style = .fill
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
contentView
UIVibrancyEffect
UIVisualEffectView
style = .fill
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
contentView
UIVibrancyEffect
UIVisualEffectView
style = .fill
contentView
UIBlurEffect
UIVisualEffectView
style = .systemMaterial
contentView
UIVibrancyEffect
UIVisualEffectView
style = .fill
contentView
Vibrant View
•
Demo
systemBackground
systemBackground
elevated level
base level
•
light white
Color
dark black
UITraitCollection
userInterfaceIdiom .phone
userInterfaceStyle .dark
userInterfaceLevel .base
Resolving Dynamic Colors
UITraitCollection
userInterfaceStyle .dark
UITraitCollection
userInterfaceStyle .dark
UIColor.systemBackground.setFill()
UIRectFill(rect)
}
}
Current Trait Collection
UIColor.systemBackground.setFill()
UIRectFill(rect)
}
}
Current Trait Collection
layer.borderColor = UIColor.label.cgColor
let layer = CALayer()
let traitCollection = view.traitCollection
layer.borderColor = UIColor.label.cgColor
let layer = CALayer()
let traitCollection = view.traitCollection
layer.borderColor = UIColor.label.cgColor
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 1
// Option 1
// Option 2
traitCollection.performAsCurrent {
layer.borderColor = UIColor.label.cgColor
}
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 2
traitCollection.performAsCurrent {
layer.borderColor = UIColor.label.cgColor
}
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 3
UITraitCollection.current = traitCollection
layer.borderColor = UIColor.label.cgColor
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 3
UITraitCollection.current = traitCollection
layer.borderColor = UIColor.label.cgColor
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 3
UITraitCollection.current = traitCollection
layer.borderColor = UIColor.label.cgColor
UITraitCollection.current = savedTraitCollection
let layer = CALayer()
let traitCollection = view.traitCollection
// Option 3
UITraitCollection.current = traitCollection
layer.borderColor = UIColor.label.cgColor
UITraitCollection.current = savedTraitCollection
When Dynamic Color Might Change
}
When Dynamic Color Might Change
}
When Dynamic Color Might Change NEW
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
// Resolve dynamic colors again
}
}
When Dynamic Color Might Change NEW
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
// Resolve dynamic colors again
}
}
Dynamic Images
Dynamic Images
UIImageView
UITraitCollection
userInterfaceStyle .dark
Dynamic Images
UIImageView
UITraitCollection
userInterfaceStyle .dark
Resolving Dynamic Images
Trait Collections
UIScreen
UIScreen
UIWindowScene
UIScreen
UIWindowScene
UIScreen
UIWindowScene
UIWindow
UIScreen
UIWindowScene
UIWindow
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIView
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIView
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIView
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIView
UIViewController
UIView
UIViewController
UIView
UIViewController
UIView
let view = UIView()
let view = UIView()
let view = UIView()
traitCollection
let view = UIView()
traitCollection
addSubview(view)
addSubview(view)
Trait Collection Changes in iOS 13 NEW
UIView.layoutSubviews()
UIViewController.viewDidLayoutSubviews()
!86
!86
UIScreen
UIWindowScene
UIWindow
UIPresentationController
UIViewController
UIView
light UIScreen
light UIWindowScene
light UIWindow
light UIPresentationController
light
UIViewController
light light
light light
UIView
light light
light UIScreen
light UIWindowScene
light UIWindow
light UIPresentationController
light
UIViewController
light dark
light dark
UIView
dark dark
Overriding User Interface Style NEW
class UIViewController {
var overrideUserInterfaceStyle: UIUserInterfaceStyle
}
class UIView {
var overrideUserInterfaceStyle: UIUserInterfaceStyle
}
Overriding User Interface Style NEW
class UIViewController {
var overrideUserInterfaceStyle: UIUserInterfaceStyle
}
class UIView {
var overrideUserInterfaceStyle: UIUserInterfaceStyle
}
class UIPresentationController {
var overrideTraitCollection: UITraitCollection?
}
class UIViewController {
func setOverrideTraitCollection(_: UITraitCollection?, forChild: UIViewController)
}
.default .lightContent
Status Bar NEW
iOS 13
.default
.lightContent
Status Bar NEW
iOS 13
.default
light dark
.darkContent .lightContent
UIActivityIndicatorView
Deprecated styles
UILabel
UITextField
UITextView
Drawing Attributed Text
Apps built using tvOS 13 SDK are expected to support dark mode
Same API