Mitul Bhadeshiya Mitul Bhadeshiya - 5 months ago 69
iOS Question

Remove underline on UIButton in iOS 7

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

enter image description here

enter image description here

How can I remove that programmatically, or by setting some property in Xcode?

Answer

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