10

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

It causing this underline in application (first picture with enabled setting, second without) enter image description here

Any idea how to programatically or in storyboard disable it?

I tried attributed text but I get same result :(

I'm newbie in Swift.

Thanks for help!

user1085907
  • 1,009
  • 2
  • 16
  • 40

6 Answers6

9

It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 3
    What rmaddy said. I opened your question to say the same thing but he beat me to it. Accessibility changes are for users with vision/perceptual problems or other deficits. If you defeat them, you make the device harder for such users to use. – Duncan C Dec 30 '15 at 18:54
  • but this way button looks awful :( – user1085907 Dec 30 '15 at 19:26
  • 1
    @user1085907 It's the user's choice, not yours. Don't fight it. Make your app look nice and work properly with no accessibility settings. Then make sure it still works (without regard to how it looks) with various accessibility settings enabled). – rmaddy Dec 30 '15 at 19:27
  • but its gonna be ugly when user have this function enabled :/ – user1085907 Dec 30 '15 at 21:19
  • It is the user's choice. And it's not ugly, it's functional. It's there for a reason. If the user enables this feature they want the underline. – rmaddy Dec 30 '15 at 21:27
  • 1
    No, the user's choice is to be able to distinguish button shapes. In this particular example, the button is completely distinguishable as-is – without the need for an underline. So this is a completely valid request and responses like this are not helpful at all. – lensovet Sep 29 '16 at 08:24
  • what I can't understand is why Apple thinks adding an underline "helps" accessibility. I'd love to remove this (objectively) ugly underlined-look on all my buttons. and in this case, if it wasn't painfully obvious, it's clearly a button as indicated by the giant blue rectangle... so why the need for a thin white underline? – user3242466 Jul 19 '17 at 23:59
1

This is an answer by user4291543 from this question Remove underline on UIButton in iOS 7

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

I found this answer works with SWFrameButton

And for all the others saying "Don't Do This", SWFrameButton is a very good example of when you would want to do this. I also think the OP's situation is a perfectly valid scenario as well...

Community
  • 1
  • 1
Hackmodford
  • 3,901
  • 4
  • 35
  • 78
1

I totally agree with @maddy's comment: It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.

But I did stumble on a way to accomplish the task at hand...

In addition to a UIButton, you'll also need to make a .png file that contains nothing (meaning the entire contents have an opacity of 0%). Go ahead and load that into your xcode project's assets.

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

see the Attributes inspector for UIButton here.

Rather than trying to defeat the underline by going to make a label perform some action via UITapGestureRecognizer, this allows you to still use a UIButton. Keeping inline with accessibility features to mark buttons for people that want to do that.

Rudi Wever
  • 11
  • 3
0

Are you sure you want to do that? Apple added an accessibility feature to mark buttons for people that want to do that. Apple will probably reject your app because it defeats a system function meant to help the disabled.

Roel Koops
  • 840
  • 2
  • 16
  • 28
  • 3
    Nope, Apple is not going to reject the app because that. – LoVo Dec 30 '15 at 19:06
  • just look on that button now, if I have some design where button looks terrible with underline what should I do? Several apps with custom background somehow evade that problem – user1085907 Dec 30 '15 at 19:28
  • please elaborate on how the existing design (without the underline) is not already marking the button? – lensovet Sep 29 '16 at 08:25
  • In my opinion, Apple ruined the feature. When first introduced, Button shapes meant button shapes. Starting with iOS 11, button shapes meant underlined text. It was better when button shapes resulted in button shapes. – Victor Engel Dec 26 '20 at 07:34
0

You could create a custom button class with a label (with clear color). If you set the text of this label instead it shouldn`t get an underline.

LoVo
  • 1,856
  • 19
  • 21
  • I had that idea too, just asking for better solution – user1085907 Dec 30 '15 at 19:27
  • No there is no way without custom implementation, but maybe you can just change the titleLabel in the awakeFromNib instead of adding an own label. – LoVo Jan 02 '16 at 08:25
0

I found the solution. All you have to do is set a picture as the background of the button. just pick a picture with the same color as the button you created.

  • for some reason when you use letter or numbers instead of a image for a UIButton it underlines the label of the button but if you set a background picture for the label inside de button it will remove the underline. you can give it a try and you will see – J.Pimentel Aug 01 '21 at 22:04