How to check if Button Shapes is enabled? [duplica

2019-07-20 03:54发布

This question already has an answer here:

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.

enter image description here

1条回答
SAY GOODBYE
2楼-- · 2019-07-20 04:43

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...
}
查看更多
登录 后发表回答