我正在尝试使用此代码在所有视图中使用UnderLine setTextAttribute [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],// NSUnderlineStyleAttributeName: @(NSUnderlineStyle
          [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],
//        NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
        (NSString *) kCTUnderlineStyleAttributeName:@(kCTUnderlineStyleDouble),
        NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]}]; 
 但它不起作用,我知道另一种方法,使用NSAttributedString创建自定义UILabel并在TitleView上设置它,但有没有其他方法来实现这个使用外观协议?
NSUnderlineStyleAttributeName应该为您完成这项工作.试试这个Dude:
NSDictionary *attributes = @{
                                 NSUnderlineStyleAttributeName: @1,
                                 NSForegroundColorAttributeName : [UIColor redColor],
                                 NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]
                                 };
    [[UINavigationBar appearance] setTitleTextAttributes:attributes]; 
 更新:
我提到Apple的文档,似乎不可能通过外观协议.
它说
“您可以使用NSString UIKit Additions Reference中描述的文本属性键为文本属性字典中的标题指定字体,文本颜色,文本阴影颜色和文本阴影偏移.”
我也试过创建新的简单项目.看不到这条线.
Apple文件:
UINavigationBar
NSString Keys for Text Attributes Dictionaries
