gpt4 book ai didi

ios - UINavigationBar setTitleTextAttributes 带下划线文本

转载 作者:可可西里 更新时间:2023-11-01 17:06:25 25 4
gpt4 key购买 nike

我正在尝试使用此代码在所有 View 中使用下划线setTextAttribute

 [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],
// NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
(NSString *) kCTUnderlineStyleAttributeName:@(kCTUnderlineStyleDouble),
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]}];

但它不起作用,我知道另一种使用 NSAttributedString 创建自定义 UILabel 并将其设置在 TitleView 上的方法,但是还有其他方法可以使用外观协议(protocol)来实现吗?

最佳答案

NSUnderlineStyleAttributeName 应该为你完成这项工作。

试试这个伙计:

    NSDictionary *attributes = @{
NSUnderlineStyleAttributeName: @1,
NSForegroundColorAttributeName : [UIColor redColor],
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]
};

[[UINavigationBar appearance] setTitleTextAttributes:attributes];

更新:

我引用了苹果的文档,貌似通过appearance protocol是不行的。

它说

“您可以使用 NSString UIKit Additions Reference 中描述的文本属性键,为文本属性字典中的标题指定字体、文本颜色、文本阴影颜色和文本阴影偏移。”

我也尝试创建新的简单项目。看不到线。

enter image description here enter image description here

Apple 文档:

UINavigationBar

NSString Keys for Text Attributes Dictionaries

关于ios - UINavigationBar setTitleTextAttributes 带下划线文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com