问题
How do I check, using UIAccessibility, if the Button Shapes option in the iOS device accessibility settings is enabled? I want to support that 'button style' on a custom made button.
回答1:
I converted the code from this post to Swift:
import UIKit
public extension UIAccessibility {
public static var isButtonShapesEnabled: Bool {
let button = UIButton()
button.setTitle("Button Shapes", for: .normal)
return button.titleLabel?.attributedText?.attribute(NSAttributedString.Key.underlineStyle, at: 0, effectiveRange: nil) != nil
}
}
Usage:
if UIAccessibility.isButtonShapesEnabled {
// Apply button shapes style to custom button...
}
来源:https://stackoverflow.com/questions/54480882/how-to-check-if-button-shapes-is-enabled