Mads K
Mads K

Reputation: 837

No visible @interface for 'UINavigationBar' declares the selector 'titleTextAttributes:'

I'm receiving the error:"No visible @interface for 'UINavigationBar' declares the selector 'titleTextAttributes:'" when trying to set the titleTextAttributes on my UINavigationBar. The .m-file looks like this:

#import "Topbar.h"

@implementation Topbar

+(UINavigationBar*)insertTopbar
{
    UINavigationBar *navBar = [ [UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    [navBar titleTextAttributes:@"MyFancyApp"];
    return navBar;
}

@end

and my .h-file looks like this:

#import <Foundation/Foundation.h>

@interface Topbar : NSObject

+(UINavigationBar*)insertTopbar;

@end

And i'm not sure, why i'm banging my head against the wall.

Upvotes: 1

Views: 852

Answers (3)

penningthoughts
penningthoughts

Reputation: 71

-(void)setNavigationBarTitleAttributes
{
    NSDictionary *attributes = @{
                                 UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
                                 UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
                                 UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
                                 UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0],
                                 };

    //Set the appearance
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];

    //OR

    [self.navigationBar setTitleTextAttributes:attributes];


    //To set the title dynamically using code, create an outlet for the UINavigationItem.
    self.navigationItem.title = @"MyFancyApp";
}

Hope this helps!

Upvotes: 1

Dimitris Bouzikas
Dimitris Bouzikas

Reputation: 4530

The correct is to setup the attributes NSDictionary *attributes and then apply:

[[UINavigationBar appearance] setTitleTextAttributes:attributes];

If you want to get attributes do this:

NSDictionary *attributes = [navBar titleTextAttributes];

Upvotes: 1

Anil Varghese
Anil Varghese

Reputation: 42977

There is no such method like titleTextAttributes: expecting a parameter. You may want to use

[navBar setTitleTextAttributes:]

And parameter should be a NSDictionary.

Upvotes: 2

Related Questions