Skip to content

Commit 6700a84

Browse files
committed
Add iOS 26 liquid glass support to Apple Music alert views
Both AlertAppleMusic16View and AlertAppleMusic17View now auto-upgrade their background to a tinted UIGlassEffect on iOS 26+, falling back to the existing blur material on older versions. A new init parameter lets callers opt out and keep the classic blur on iOS 26.
1 parent e8a0208 commit 6700a84

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ alertView.titleLabel.font = UIFont.systemFont(ofSize: 21)
109109
alertView.titleLabel.textColor = .white
110110
```
111111

112+
### Liquid Glass (iOS 26+)
113+
114+
On iOS 26 and later, both `AlertAppleMusic16View` and `AlertAppleMusic17View` automatically upgrade their background to a tinted `UIGlassEffect`. On older iOS versions they fall back to the original blur material, so no caller changes are required.
115+
116+
If you want to opt out and force the classic blur on iOS 26+, pass `forceNonGlass: true` at construction time:
117+
118+
```swift
119+
let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done, forceNonGlass: true)
120+
121+
// also available on the iOS 16 style
122+
let alertView16 = AlertAppleMusic16View(title: "Added to Library", subtitle: nil, icon: .done, forceNonGlass: true)
123+
```
124+
125+
The flag must be set at init — the background effect is built during initialisation, so a property change afterwards would have no effect.
126+
112127
## Present & Dismiss
113128

114129
You can present and dismiss alerts manually via view.

Sources/AlertKit/Views/AlertAppleMusic16View.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol {
1111
public let titleLabel: UILabel?
1212
public let subtitleLabel: UILabel?
1313
public let iconView: UIView?
14+
15+
private let forceNonGlass: Bool
1416

1517
public static var defaultContentColor = UIColor { trait in
1618
switch trait.userInterfaceStyle {
@@ -26,23 +28,36 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol {
2628
fileprivate var completion: (()->Void)? = nil
2729

2830
private lazy var backgroundView: UIVisualEffectView = {
29-
let view: UIVisualEffectView = {
31+
let effect: UIVisualEffect = {
3032
#if !os(tvOS)
33+
if #available(iOS 26, *), !forceNonGlass {
34+
let glass = UIGlassEffect()
35+
glass.tintColor = UIColor { trait in
36+
switch trait.userInterfaceStyle {
37+
case .dark: return UIColor.white.withAlphaComponent(0.12)
38+
default: return UIColor.black.withAlphaComponent(0.06)
39+
}
40+
}
41+
return glass
42+
}
3143
if #available(iOS 13.0, *) {
32-
return UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
44+
return UIBlurEffect(style: .systemThickMaterial)
3345
} else {
34-
return UIVisualEffectView(effect: UIBlurEffect(style: .light))
46+
return UIBlurEffect(style: .light)
3547
}
3648
#else
37-
return UIVisualEffectView(effect: UIBlurEffect(style: .light))
49+
return UIBlurEffect(style: .light)
3850
#endif
3951
}()
52+
let view = UIVisualEffectView(effect: effect)
4053
view.isUserInteractionEnabled = false
4154
return view
4255
}()
43-
44-
public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil) {
45-
56+
57+
public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil, forceNonGlass: Bool = false) {
58+
59+
self.forceNonGlass = forceNonGlass
60+
4661
if let title = title {
4762
let label = UILabel()
4863
label.font = UIFont.preferredFont(forTextStyle: .title2, weight: .bold)

Sources/AlertKit/Views/AlertAppleMusic17View.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol, AlertViewInternal
1212
public let titleLabel: UILabel?
1313
public let subtitleLabel: UILabel?
1414
public let iconView: UIView?
15+
16+
private let forceNonGlass: Bool
1517

1618
public static var defaultContentColor = UIColor { trait in
1719
#if os(visionOS)
@@ -38,14 +40,29 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol, AlertViewInternal
3840
hostView.isUserInteractionEnabled = false
3941
return hostView
4042
#else
41-
let view = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
43+
let effect: UIVisualEffect
44+
if #available(iOS 26, *), !forceNonGlass {
45+
let glass = UIGlassEffect()
46+
glass.tintColor = UIColor { trait in
47+
switch trait.userInterfaceStyle {
48+
case .dark: return UIColor.white.withAlphaComponent(0.12)
49+
default: return UIColor.black.withAlphaComponent(0.06)
50+
}
51+
}
52+
effect = glass
53+
} else {
54+
effect = UIBlurEffect(style: .systemMaterial)
55+
}
56+
let view = UIVisualEffectView(effect: effect)
4257
view.isUserInteractionEnabled = false
4358
return view
4459
#endif
4560
}()
4661

47-
public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil) {
48-
62+
public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil, forceNonGlass: Bool = false) {
63+
64+
self.forceNonGlass = forceNonGlass
65+
4966
if let title = title {
5067
let label = UILabel()
5168
label.font = UIFont.preferredFont(forTextStyle: .body, weight: .semibold, addPoints: -2)

0 commit comments

Comments
 (0)