如何检查按钮形状设置是否启用

如何检查按钮形状设置是否启用

本文介绍了如何检查按钮形状设置是否启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 7.1 包含一个新的辅助功能设置调用按钮形状,这会导致某些按钮文本自动带有下划线.有没有办法检测这种模式,或者为单个 UIButton 自定义它?

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 UIButtons?

(这允许更改按钮标签,例如破折号或下划线,以便在加下划线时,它们看起来不像等号等)

(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;
}

这篇关于如何检查按钮形状设置是否启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:00