Ignoring the dynamic type in iOS: Accessibility

后端 未结 4 1907
慢半拍i
慢半拍i 2020-12-10 14:19

Is there a way to completely ignore dynamic type/font size settings in iOS apps? I mean is there a way like a plist entry so that I can disable it completely. I understand t

4条回答
  •  有刺的猬
    2020-12-10 14:39

    Just provide Swift 4 fix to @gebirgsbärbel answer. "preferredContentSizeCategory" in Objective-C is a method, but in Swift it is a read-only variable. So in your AppDelegate is like this:

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
        // MARK: - UIApplicationDelegate
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    
            UIApplication.classInit
    
            self.window = UIWindow(frame: UIScreen.main.bounds)
            ...
            self.window?.makeKeyAndVisible()
            return true
        }
    }
    
    // MARK: - Fix Dynamic Type
    
    extension UIApplication {
    
        static let classInit: Void = {
            method_exchangeImplementations(
                class_getInstanceMethod(UIApplication.self, #selector(getter: fixedPreferredContentSizeCategory))!,
                class_getInstanceMethod(UIApplication.self, #selector(getter: preferredContentSizeCategory))!
            )
        }()
    
        @objc
        var fixedPreferredContentSizeCategory: UIContentSizeCategory {
            return .large
        }
    }
    

提交回复
热议问题