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?

+3


source to share


1 answer


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.

enter image description hereenter image description here

Apple Documentation:

UINavigationBar

NSString Keys for text attributes Dictionaries

+7


source







All Articles