问题描述
iOS 7.1包括一个名为按钮形状的新辅助功能设置,该设置会导致某些按钮文本自动带下划线。有没有办法检测此模式,或者为单个 UIButton
s自定义它?
iOS 7.1 includes a new Accessibility setting calls Button Shapes that causes some button text to be automatically underlined. Is there a way to detect this mode, or customize it for individual UIButton
s?
(这允许更改按钮标签(例如破折号或下划线),以便在下划线时看起来不像等号。)
(This to allow changing button labels such as a dash or underscore so that when underlined, they don't look like an equals sign, etc.)
推荐答案
看起来您可以请求按钮标签的属性并进行测试,以查看它是否包含NSUnderlineStyleAttributeName属性。如果删除NSUnderlineStyleAttributeName属性,系统会将其放回原处,因此似乎可以将窍门明确地将标签的下划线属性设置为0。我在自定义按钮中添加了以下内容:
It looks like you can request the button label's attributes and test to see if it contains an NSUnderlineStyleAttributeName attribute. If you remove the NSUnderlineStyleAttributeName attribute the system will put it right back so it seems the trick is to explicitly set the label's underline attribute to 0. I've added the following to my custom button:
- (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;
}
这篇关于如何检查“按钮形状”设置是否已启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!