删除iOS 7中UIButton的下划线

时间:2014-04-23 13:55:03

标签: ios cocoa-touch uibutton ios7.1

任何人都知道如何删除由于辅助功能而出现的UIButton下划线?

(我知道这是因为用户打开了“按钮形状”)

enter image description here

enter image description here

如何以编程方式删除它,或者在Xcode中设置一些属性?

9 个答案:

答案 0 :(得分:12)

让我直截了当。 Apple添加了一个辅助功能,允许用户根据需要标记带下划线的按​​钮。

你想要一种方法来打败这个功能,专门用于帮助有障碍的人使用他们的设备,当这个功能是用户必须要求的时候。

为什么?

很可能无法使用标准按钮。如果你确实找到了一种方法,Apple可能会拒绝你的应用程序,因为它会破坏一个旨在帮助残疾人的系统功能。

所以答案是:不要这样做。

答案 1 :(得分:9)

您应该转到设置>一般>辅助功能和打开/关闭按钮形状,然后重新访问相关的应用程序。打开此控件时,您应该只看到下划线和形状,这是为了指示哪些看起来像文本的按钮实际上可以替代那些具有辅助功能需求的按钮。

答案 2 :(得分:7)

检查以下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];
}];

•与督察/ IB: 选择UIButton 显示Attributes Inspector
Text设置应位于Attributed。选择文字,点击喜欢的项目,删除下划线,将其设置为none enter image description here

答案 3 :(得分:7)

将背景图像设置为按钮。

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

答案 4 :(得分:4)

“按钮形状”是iOS 7.1中的新辅助功能选项。如果用户想要激活此选项,则无法执行任何操作。这是用户的选择。

答案 5 :(得分:3)

如果按钮带有下划线由于可访问性按钮形状选项,则可以使用图像而不是文本来设置按钮标题。只需创建将绘制文本的图像并将其设置为按钮。在这种情况下,iOS无法识别文本,也不会插入下划线 您可以将其视为黑客但不是明确的解决方案。

答案 6 :(得分:1)

您无法关闭此辅助功能。

如果你真的想摆脱它,可以自定义UILabel或UIView with UITapGestureRecognizer

答案 7 :(得分:1)

首先从已设置的按钮获取attribute string

NSMutableAttributedString *attrStr = [[yourBtnHere  attributedTitleForState:UIControlStateNormal] mutableCopy];

使用removeAttribute删除属性,如下所示:

[attrStr removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0,[attrStr length])];
[attrStr addAttribute: NSUnderlineStyleAttributeName value: [NSNumber numberWithInt:0] range: [attrStr length]];

使用addAttribute重置属性,如下所示:

UIColor *textBtncolor = [UIColor blackColor];
[attrStr addAttribute:NSForegroundColorAttributeName value:textBtncolor range:NSMakeRange(0, attrStr.length)];

现在在按钮中设置属性字符串

[yourBtnHere setAttributedTitle:[attrStr copy] forState:UIControlStateNormal];

答案 8 :(得分:0)

从模拟器中的UIButton中删除不需要的蓝色图层

转到设置>一般>辅助功能和关闭按钮形状,然后重新运行应用程序,它将删除不需要的蓝色图层。