How to check if Button Shapes is enabled? [duplicate]

怎甘沉沦 提交于 2020-01-04 07:44:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!