导航栏标题字体大小 [英] Navigation Bar Title Font Size

查看:352
本文介绍了导航栏标题字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在iPhone应用中更改一个视图控制器的导航栏标题文本的大小。我正在使用iOS5,并尝试了以下代码:

  if([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes :) ]){
NSLog(@***支持方法(iOS 5):setTitleTextAttributes:);
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@AmericanTypewritersize:20.0f],UITextAttributeFont,
[UIColor blackColor],UITextAttributeTextColor,
[ UIColor grayColor],UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f,1.0f)],UITextAttributeTextShadowOffset,
nil]];
}

但是这仅适用于tabBarItem。

解决方案

您需要获取导航栏属性并使用 @property(nonatomic,copy)NSDictionary * titleTextAttributes



有关详细信息,请参阅 UINavigationBar类参考自定义UINavigationBar部分



更好地理解你的问题:你有什么类型的控制器? / p>

编辑

  [self.navigationController .navigationBar setTitleTextAttributes:...]; 

如果您在推送中访问 navigationController 控制器。

  [navigationController.navigationBar setTitleTextAttributes:...]; 

如果 navigationController 是您当前的的UINavigationController 。例如,如果您有以下代码,则可以使用此选项:

  UINavigationController * navigationController = ...; 
[navigationController.navigationBar setTitleTextAttributes:...];


I need to change the size of the Navigation Bar title text for one view controller in my iPhone app. I'm using iOS5, and tried the following code:

if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes:)]) {
    NSLog(@"*** Support method(iOS 5): setTitleTextAttributes:");
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
                                                [UIColor blackColor], UITextAttributeTextColor,
                                                [UIColor grayColor], UITextAttributeTextShadowColor,
                                                [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
                                                nil]];
}

However this only applies to the tabBarItem.

解决方案

You need to grab the navigation bar property and the use @property(nonatomic, copy) NSDictionary *titleTextAttributes.

For further info see UINavigationBar Class Reference and Customizing UINavigationBar section.

To understand better your question: What type of controller do you have?

EDIT

[self.navigationController.navigationBar setTitleTextAttributes:...];

if you access the navigationController within a pushed controller.

[navigationController.navigationBar setTitleTextAttributes:...];

if navigationController is your current UINavigationController. This could be used when for example if you have the following code:

UINavigationController* navigationController = ...;
[navigationController.navigationBar setTitleTextAttributes:...];

这篇关于导航栏标题字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆