如何在ios 5和ios 6中自定义导航栏?
问题描述:
正如我在这里搜索时看到的那样,在同一主题上有很多问题,但我真的不知道要使用哪些代码以及将它们放在哪里。如何在ios 5和ios 6中自定义导航栏?
我只是想将导航栏更改为具有自己的背景图像的自定义栏。
我看过一些代码,但我真的很新,所以我不知道该怎么做!
-Simon
答
//first put this code in AppDelegate.m
in this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//code: navigationbar set image and fontcolor:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"your_navigationimg_bg"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.0 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes: @{
UITextAttributeTextShadowColor: [UIColor clearColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:@"AppleGothic" size:20.0f]
}];
[self.window makeKeyAndVisible];
return YES;
}
//second: put this code in RootViewController.m
in this method:
- (void)viewDidLoad
{
[email protected]"your title";
[super viewDidLoad];
}
您的屏幕截图显示了一个标准导航栏。您可以使用文档中描述的外观方法自定义导航栏。你能解释你遇到麻烦的部分吗? – jrturton
但我在哪里把代码?而我不知道客观的c好,努力吧! – SimonZ1