ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.86k stars 1.7k forks source link

下划线在UIButton上不显示 #776

Open HouWan opened 6 years ago

HouWan commented 6 years ago

环境:Xcode 9.2 设备:iOS 11.2 模拟器 真机同样问题

代码:

NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc] initWithString:storeName];
[textAtt yy_setFont:HWFont(12) range:NSMakeRange(0, text.length)];
[textAtt yy_setColor:[UIColor whiteColor] range:NSMakeRange(0, text.length)];

YYTextDecoration *line = [YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:@(1) color:[UIColor blueColor]];
    [textAtt yy_setTextUnderline:line range:NSMakeRange(0, text.length)];

赋值到UILabelYYLabel上显示下划线,赋值到UIButton上不显示下划线。

使用原生下划线方法,无论UILabelYYLabelUIButton,都能显示下划线

[textAtt addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, text.length)];

HouWan commented 6 years ago

wechatimg229

sinno93 commented 6 years ago

仅仅是加下划线的试试这个? [text yy_setUnderlineStyle:NSUnderlineStyleSingle range:text.yy_rangeOfAll];