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\")
Set background image to the button.
[yourBtnHere setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal];
Let me get this straight. Apple added an accessibility feature that lets users mark buttons with underlines if they want to.
You want a way to defeat this feature, specifically designed to help people with handicaps use their devices, when the feature is something that the user has to ask for.
Why?
It is very likely not possible using standard buttons. If you did figure out a way to do it, Apple would likely reject your app because it defeats a system function meant to help the disabled.
So the answer is: Don't do that.
If button is underlined due accessibility button shape option then you could set button title by using image but not by text. Simply create image where text will be drawn and set it to the button. In this case iOS can't recognize text there and won't insert underline.
You could consider it as hack but not as clear solution.
The "Button shapes" is a new accessibility option in iOS 7.1. If the user want to have this option activated, there is nothing you can do. This is the user's choice.
You can't turn off this accessibility feature.
Make a custom UILabel or UIView with UITapGestureRecognizer if you really want to get rid of it.
First get attribute string
from button which has been set.
NSMutableAttributedString *attrStr = [[yourBtnHere attributedTitleForState:UIControlStateNormal] mutableCopy];
Remove Attribute using removeAttribute
like this :
[attrStr removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0,[attrStr length])];
[attrStr addAttribute: NSUnderlineStyleAttributeName value: [NSNumber numberWithInt:0] range: [attrStr length]];
Reset attribute using addAttribute
like this:
UIColor *textBtncolor = [UIColor blackColor];
[attrStr addAttribute:NSForegroundColorAttributeName value:textBtncolor range:NSMakeRange(0, attrStr.length)];
Now set attribute string in your button
[yourBtnHere setAttributedTitle:[attrStr copy] forState:UIControlStateNormal];