Xcode 如何在ios 5和ios 6中自定义导航栏?
正如我在这里搜索时看到的,在同一个主题上有很多问题,但我真的不知道应该使用哪些代码以及将它们放在哪里 我只想将导航栏更改为具有自己背景图像的自定义栏 我确实看到一些代码,但我真的是新的,所以我不知道如何做到这一点Xcode 如何在ios 5和ios 6中自定义导航栏?,xcode,ios5,uinavigationcontroller,ios6,uinavigationbar,Xcode,Ios5,Uinavigationcontroller,Ios6,Uinavigationbar,正如我在这里搜索时看到的,在同一个主题上有很多问题,但我真的不知道应该使用哪些代码以及将它们放在哪里 我只想将导航栏更改为具有自己背景图像的自定义栏 我确实看到一些代码,但我真的是新的,所以我不知道如何做到这一点 -Simon使用外观属性 [[UINavigationBar外观]setBackgroundImage:yourimage for BarMetrics:UIBarMetricsDefault] 使用外观属性 //first put this code in AppDeleg
-Simon使用外观属性
[[UINavigationBar外观]setBackgroundImage:yourimage for BarMetrics:UIBarMetricsDefault] 使用外观属性
//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
{
self.navigationItem.title=@"your title";
[super viewDidLoad];
}
[[UINavigationBar外观]setBackgroundImage:yourimage for BarMetrics:UIBarMetricsDefault] 您的屏幕截图显示了一个标准的导航栏。您可以使用文档中描述的外观方法自定义导航栏。你能解释一下你在哪一部分遇到了麻烦吗?但我该把代码放在哪里呢?我不知道Objective c有多好,正在努力!您的屏幕截图显示了一个标准的导航栏。您可以使用文档中描述的外观方法自定义导航栏。你能解释一下你在哪一部分遇到了麻烦吗?但我该把代码放在哪里呢?我不知道Objective c有多好,正在努力!我搜索了所有地方,但它只是一个旧代码和类似的东西的混搭。我不知道该把它放在哪里!如果您想为所有类添加导航栏,请在app delegate中尝试,或者将其添加到您想要添加导航的视图控制器中,bari已经搜索过了,但它只是旧代码和类似内容的混搭。我不知道该把它放在哪里!如果要为所有类添加导航栏,请在app delegate中尝试,或将其添加到要添加导航栏的视图控制器中
//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
{
self.navigationItem.title=@"your title";
[super viewDidLoad];
}