UINavigationBar setTitleTextAttributes with text UnderLine
I am trying setTextAttribute
with UnderLine in all views using this code
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],
// NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
(NSString *) kCTUnderlineStyleAttributeName:@(kCTUnderlineStyleDouble),
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]}];
but it doesn't work, I know a different approach using create UILabel
with NSAttributedString
and setting it to TitleView, but is there any other way to achieve this using appearance protocol?
source to share
NSUnderlineStyleAttributeName should do the job for you.
Try this dude:
NSDictionary *attributes = @{
NSUnderlineStyleAttributeName: @1,
NSForegroundColorAttributeName : [UIColor redColor],
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:17]
};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
Update:
I was referring to Apple documentation, It seems this is not possible on the appearance protocol.
It says
"You can specify the font, text color, shadow text color, and shadow text offset for the title in the text attribute dictionary using the text attribute keys described in the NSString UIKit Adddition Reference."
I tried to create a new simple project. Failed to see the line.
Apple Documentation:
source to share