我收到错误:“尝试在我的UINavigationBar上设置titleTextAttributes时,'UINavigationBar'没有可见的@interface声明选择器'titleTextAttributes:'”。 .m文件如下所示:
#import "Topbar.h"
@implementation Topbar
+(UINavigationBar*)insertTopbar
{
UINavigationBar *navBar = [ [UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navBar titleTextAttributes:@"MyFancyApp"];
return navBar;
}
@end
和我的.h文件看起来像这样:
#import <Foundation/Foundation.h>
@interface Topbar : NSObject
+(UINavigationBar*)insertTopbar;
@end
我不确定,为什么我的头撞在墙上。
答案 0 :(得分:2)
没有像titleTextAttributes:
这样的方法期望参数。您可能想要使用
[navBar setTitleTextAttributes:]
参数应为NSDictionary
。
答案 1 :(得分:1)
正确的是设置属性NSDictionary *attributes
,然后应用:
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
如果您想获取属性,请执行以下操作:
NSDictionary *attributes = [navBar titleTextAttributes];
答案 2 :(得分:1)
-(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"; }
希望这有帮助!