如何在UILabel上为Underline创建属性?

Sai*_*son 2 objective-c nsattributedstring ios

我的代码已经有了这个属性,但是如何为下划线添加属性?

NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: 
boldFont, NSFontAttributeName, foregroundColor, NSForegroundColorAttributeName, nil];
Run Code Online (Sandbox Code Playgroud)

Mar*_*bri 13

只需添加一个NSUnderlineStyleAttributeName@(NSUnderlineStyleSingle)作为值:

NSDictionary *attrs = @{ NSFontAttributeName : boldFont, 
                         NSForegroundColorAttributeName : foregroundColor,
                         NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle) };
Run Code Online (Sandbox Code Playgroud)