Search code examples
ios7accessibility

How to check if the Button Shapes setting is enabled?


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.)


Solution

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