|
1 | 1 | // Copyright © 2019 Saleem Abdulrasool < [email protected]>
|
2 | 2 | // SPDX-License-Identifier: BSD-3-Clause
|
3 | 3 |
|
| 4 | +import class Foundation.NSNotification |
| 5 | + |
| 6 | +/// Constants that indicate the preferred size of your content. |
| 7 | +public struct ContentSizeCategory: Equatable, Hashable, RawRepresentable { |
| 8 | + public typealias RawValue = String |
| 9 | + |
| 10 | + public var rawValue: RawValue |
| 11 | + |
| 12 | + public init(rawValue: RawValue) { |
| 13 | + self.rawValue = rawValue |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +extension ContentSizeCategory { |
| 18 | + // MARK - Font Sizes |
| 19 | + |
| 20 | + /// An unspecified font size. |
| 21 | + public static var unspecified: ContentSizeCategory { |
| 22 | + ContentSizeCategory(rawValue: "_UICTContentSizeCategoryUnspecified") |
| 23 | + } |
| 24 | + |
| 25 | + /// An extra-small font. |
| 26 | + public static var extraSmall: ContentSizeCategory { |
| 27 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryXS") |
| 28 | + } |
| 29 | + |
| 30 | + /// A small font. |
| 31 | + public static var small: ContentSizeCategory { |
| 32 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryS") |
| 33 | + } |
| 34 | + |
| 35 | + /// A medium-sized font. |
| 36 | + public static var medium: ContentSizeCategory { |
| 37 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryM") |
| 38 | + } |
| 39 | + |
| 40 | + /// A large font. |
| 41 | + public static var large: ContentSizeCategory { |
| 42 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryL") |
| 43 | + } |
| 44 | + |
| 45 | + /// An extra-large font. |
| 46 | + public static var extraLarge: ContentSizeCategory { |
| 47 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryXL") |
| 48 | + } |
| 49 | + |
| 50 | + /// A font that is larger than the extra-large font but smaller than the |
| 51 | + /// largest font size available. |
| 52 | + public static var extraExtraLarge: ContentSizeCategory { |
| 53 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXL") |
| 54 | + } |
| 55 | + |
| 56 | + /// The largest font size. |
| 57 | + public static var extraExtraExtraLarge: ContentSizeCategory { |
| 58 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryXXXL") |
| 59 | + } |
| 60 | + |
| 61 | + // MARK - Accessibility Sizes |
| 62 | + |
| 63 | + /// A medium font size that reflects the current accessibility settings. |
| 64 | + public static var accessibilityMedium: ContentSizeCategory { |
| 65 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityM") |
| 66 | + } |
| 67 | + |
| 68 | + /// A large font size that reflects the current accessibility settings. |
| 69 | + public static var accessibilityLarge: ContentSizeCategory { |
| 70 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityL") |
| 71 | + } |
| 72 | + |
| 73 | + /// An extra-large font size that reflects the current accessibility settings. |
| 74 | + public static var accessibilityExtraLarge: ContentSizeCategory { |
| 75 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXL") |
| 76 | + } |
| 77 | + |
| 78 | + /// A font that is larger than the extra-large font but not the largest |
| 79 | + /// available, reflecting the current accessibility settings. |
| 80 | + public static var accessibilityExtraExtraLarge: ContentSizeCategory { |
| 81 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXL") |
| 82 | + } |
| 83 | + |
| 84 | + /// The largest font size that reflects the current accessibility settings. |
| 85 | + public static var accessibilityExtraExtraExtraLarge: ContentSizeCategory { |
| 86 | + ContentSizeCategory(rawValue: "UICTContentSizeCategoryAccessibilityXXXL") |
| 87 | + } |
| 88 | + |
| 89 | + // MARK - Font Size Change Notifications |
| 90 | + |
| 91 | + /// A notification that posts when the user changes the preferred content size |
| 92 | + /// setting. |
| 93 | + /// |
| 94 | + /// This notification is sent when the value in the |
| 95 | + /// `preferredContentSizeCategory` property changes. The `userInfo` dictionary |
| 96 | + /// of the notification contains the `newValueUserInfoKey` key, which reflects |
| 97 | + /// the new setting. |
| 98 | + public static var didChangeNotification: NSNotification.Name { |
| 99 | + NSNotification.Name(rawValue: "UIContentSizeCategoryDidChangeNotification") |
| 100 | + } |
| 101 | + |
| 102 | + /// A key that reflects the new preferred content size. |
| 103 | + /// |
| 104 | + /// This key's value is an `NSString` object that reflects the new value of |
| 105 | + /// the `preferredContentSizeCategory` property. |
| 106 | + public static var newValueUserInfoKey: String { |
| 107 | + "UIContentSizeCategoryNewValueUserInfoKey" |
| 108 | + } |
| 109 | +} |
| 110 | + |
4 | 111 | /// The centralised point of control and coordination for running applications.
|
5 | 112 | open class Application: Responder {
|
6 | 113 | internal var information: Information?
|
|
0 commit comments