ios - 如何在 UILabel 上为下划线创建属性?

标签 ios objective-c nsattributedstring

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

NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: 
boldFont, NSFontAttributeName, foregroundColor, NSForegroundColorAttributeName, nil];

最佳答案

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

NSDictionary *attrs = @{ NSFontAttributeName : boldFont, 
                         NSForegroundColorAttributeName : foregroundColor,
                         NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle) };

关于ios - 如何在 UILabel 上为下划线创建属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18819665/

相关文章:

c# - Xamarin 加载操作失败

ios - iOS 中的复杂代码

objective-c - 使用 NSView 在中心显示 NSAttributedString

ios - 如何允许将 NSAttributedString 文本输入到 UITextView 中?

html - 如何根据html标签在UILabel中显示html文本?

ios - UIButton 触摸事件重叠

ios - 字符到 NSString ObjC

iphone - awakeFromInsert 从未调用过

iphone - 突出显示的阴影颜色

c++ - ARC 和 C++ 对象内的 Objective C 对象会发生什么?