hot*_*aw2 13 accessibility ios7
iOS 7.1包含一个新的"辅助功能"设置,调用"按钮形状"可以使某些按钮文本自动加下划线.有没有办法检测这种模式,或为个人UIButtons 定制?
(这允许更改按钮标签,例如破折号或下划线,以便在加下划线时,它们看起来不像等号等)
从 iOS 14 开始,您可以使用UIAccessibility.buttonShapesEnabled或UIAccessibilityButtonShapesEnabled(),启用该设置后为 true。
看起来您可以请求按钮标签的属性并测试它是否包含 NSUnderlineStyleAttributeName 属性。如果删除 NSUnderlineStyleAttributeName 属性,系统会将其放回原处,因此看来技巧是将标签的下划线属性显式设置为 0。我已将以下内容添加到我的自定义按钮中:
- (void) adjustLabelProperties // override underline attribute
{
NSMutableAttributedString *attributedText = [self.titleLabel.attributedText mutableCopy];
[attributedText addAttribute: NSUnderlineStyleAttributeName value: @(0) range: NSMakeRange(0, [attributedText length])];
self.titleLabel.attributedText = attributedText;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1666 次 |
| 最近记录: |