Remove underline on UIButton in iOS 7

前端 未结 9 2189
北海茫月
北海茫月 2020-12-10 14:26

Any one know how to remove the UIButton underline that appears because of Accessibility?

(I know it\'s because the user turned on \"Button Shapes\")

相关标签:
9条回答
  • 2020-12-10 15:17

    Check below code :

    NSMutableAttributedString *attrStr = [[yourBtnHere attributedTitleForState:UIControlStateNormal] mutableCopy];//or whatever the state you want
    [attrStr enumerateAttributesInRange:NSMakeRange(0, [attrStr length])
                                options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
                             usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop)
    {
        NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes];
        [mutableAttributes removeObjectForKey:NSUnderlineStyleAttributeName];
        [attrStr setAttributes:mutableAttributes range:range];
    }];
    

    • With the inspector/IB: Select your UIButton.
    Show the Attributes Inspector.
    The Textsettings should be in Attributed. Select the text, click on the fond item remove the Underlining setting it at none.
    enter image description here

    0 讨论(0)
  • 2020-12-10 15:17

    You should go to Settings > General > Accessibility and turn on/off Button Shapes and then revisit the app in question. You should only see underlines and shapes when this control is on, and this is to indicate what buttons that look like text are actually tappable for those with accessibility needs.

    0 讨论(0)
  • 2020-12-10 15:17

    To remove the unwanted Blue colour layer from UIButton in simulator

    go to Settings > General > Accessibility and turn off Button Shapes and then reRun the app it will remove the unwanted blue layer.

    0 讨论(0)
提交回复
热议问题