Ios7 UINavigationBar更改标题文本颜色和字体大小
我想更改导航标题的字体和颜色。因此,我已经完成了下面的代码。但它不起作用Ios7 UINavigationBar更改标题文本颜色和字体大小,ios7,uinavigationbar,iphone-5,Ios7,Uinavigationbar,Iphone 5,我想更改导航标题的字体和颜色。因此,我已经完成了下面的代码。但它不起作用 if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:@"MyFavoriteFont" size:20.0],
NSFontAttributeName,
nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
NSLog(@"setTitleTextAttributes");
}
为什么此代码不起作用?将属性应用于Navigationcontroller实例
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:@"MyFavoriteFont" size:20.0],
NSFontAttributeName,
nil];
[self.transitionNavController.navigationBar setTitleTextAttributes:navbarTitleTextAttributes];
}
如果([[[UIDevice currentDevice]systemVersion]floatValue]<7.0),希望这有助于…
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
@{
UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:@"ArialMT" size:18.0f]
}];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
else
{
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// Uncomment to change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Uncomment to assign a custom backgroung image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
// Uncomment to change the back indicator image
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@""]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@""]];
// Uncomment to change the font style of the title
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:@"ArialMT" size:18.0], NSFontAttributeName, nil]];
CGFloat verticalOffset = 0;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
{
[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“nav_bg.png”]forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar外观]setTitleTextAttributes:
@{
UITextAttributeTextColor:[UIColor whiteColor],UITextAttributeTextShadowColor:[UIColor clearColor],UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetMake(0.0f,1.0f)],UITextAttributeFont:[UIFont fontWithName:@“ArialMT”大小:18.0f]
}];
CGFloat垂直偏移=-4;
[[UINavigationBar外观]setTitleVerticalPositionAdjustment:BarMetrics的垂直偏移量:UIBarMetricsDefault];
}
其他的
{
[[UINavigationBar外观]SetPartIntColor:[UIColor whiteColor]];
//取消注释以更改“后退”按钮的颜色
[[UINavigationBar外观]setTintColor:[UIColor whiteColor]];
//取消注释以指定自定义背景图像
[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“nav_bg.png”]forBarMetrics:UIBarMetricsDefault];
//取消注释以更改后指示器图像
[[UINavigationBar外观]设置指示符号图像:[UIImage ImageName:@”“];
[[UINavigationBar外观]收件指示符号转换图像:[UIImage ImageName:@”“];
//取消注释以更改标题的字体样式
NSShadow*shadow=[[NSShadow alloc]init];
shadow.shadowColor=[UIColor colorWithRed:0.0绿色:0.0蓝色:0.0 alpha:0.8];
shadow.shadowOffset=CGSizeMake(0,1);
[[UINavigationBar外观]setTitleTextAttributes:[NSDictionary Dictionary With Objects and Keys:[UIColor ColorWith红色:245.0/255.0绿色:245.0/255.0蓝色:245.0/255.0 alpha:1.0],NSForegroundColorAttributeName,shadow,NSShadowAttributeName,[UIFontWithName:@“ArialMT”大小:18.0],NSFontAttributeName,nil];
CGFloat垂直偏移=0;
[[UINavigationBar外观]setTitleVerticalPositionAdjustment:BarMetrics的垂直偏移量:UIBarMetricsDefault];
}