首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改NavigationItem的字体

更改NavigationItem的字体
EN

Stack Overflow用户
提问于 2010-05-05 16:19:54
回答 10查看 27.4K关注 0票数 19

我已经使用以下代码更改了NavigationItem的标题:

代码语言:javascript
复制
self.navigationItem.title = @"My Name is ABC";

如何更改字体大小和字体?

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2010-05-05 16:51:03

示例代码:

代码语言:javascript
复制
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:8.0];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = @"Sample custom Title With small Fonts ";
self.navigationItem.titleView = label;
票数 32
EN

Stack Overflow用户

发布于 2013-01-03 05:01:26

从iOS5+开始,您可以使用UIAppearance protocol更改导航标题的字体,代码如下:

代码语言:javascript
复制
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"Helvetica-Bold" size:18] forKey:UITextAttributeFont];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
票数 18
EN

Stack Overflow用户

发布于 2013-04-04 18:58:07

由于使用了iOS5,您可以像这样使用新的titleTextAttributes属性:

代码语言:javascript
复制
NSMutableDictionary *newAttributes = [[NSMutableDictionary alloc] init]; 
[newAttributes setObject:[UIFont boldSystemFontOfSize:18] forKey:UITextAttributeFont];
[self.navigationController.navigationBar setTitleTextAttributes:newAttributes];

可能的关键字包括:

代码语言:javascript
复制
UITextAttributeFont
UITextAttributeTextColor
UITextAttributeTextShadowColor
UITextAttributeTextShadowOffset
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2771541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档