加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 带有UnderLine Text的UINavigationBar setTitleTextAttri

发布时间:2020-12-14 17:12:58 所属栏目:百科 来源:网络整理
导读:我正在尝试使用此代码在所有视图中使用UnderLine setTextAttribute [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],// NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),(NSString
我正在尝试使用此代码在所有视图中使用UnderLine setTextAttribute

[[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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读