Swift UIButton - How to remove underline?

I have a problem when this option "Button Shapes" is enabled in the iOS settings enter image description here

This causes this underline in the application (the first shot with the setting turned on, the second without) enter image description here

Any idea how to disable it programmatically or in a storyboard?

I tried the sent text, but I get the same result :(

I am new to Swift.

Thanks for the help!

+6
source share
5 answers

It's not a problem. You should not try to resist any changes in accessibility set by the user. They are there for some reason.

+7
source

Do you really want to do this? Apple has added an accessibility feature to mark buttons for people who want to do this. Apple is likely to reject your application because it defeats a system feature designed to help people with disabilities.

0
source

You can create your own class of buttons with a label (with a clear color). If you set the text for this shortcut, it should not receive underlining.

0
source

This is user4291543 answer from this question Remove underscore on UIButton in iOS 7

[yourBtnHere setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal]; 

I found this answer works with SWFrameButton

And for everyone else saying “Do not Do This,” SWFrameButton is a very good example of when you want to do this. I also think that the situation with the OP is a perfectly acceptable scenario ...

0
source

I totally agree with @maddy's comment: This is not a problem. You should not try to resist any changes in accessibility set by the user. They are there for some reason.

But I came across a way to accomplish the task ...

In addition to UIButton, you will also need to create a .png file that does not contain anything (which means that all content has 0% opacity). Go and load it into your xcode project assets.

Now go and set the Background button for this image you just provided. (In my case, I called it clear ). This will remove the underline from the button text. However, now you cannot see the borders of the button. This can be solved by changing the background of the View button. Go ahead and select any color for the Background View property, and now the View background clearly defines the borders of the buttons. You can see this because your clear.png has an opacity of 0%.

see attribute inspector for UIButton here.

Instead of trying to defeat the underscore by making a shortcut, follow some steps with the UITapGestureRecognizer, this will allow you to still use UIButton. Preservation of built-in accessibility functions to indicate buttons for people who want to do this.

0
source

All Articles