我已经使用以下代码更改了NavigationItem的标题:
self.navigationItem.title = @"My Name is ABC";如何更改字体大小和字体?
发布于 2010-05-05 16:51:03
示例代码:
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;发布于 2013-01-03 05:01:26
从iOS5+开始,您可以使用UIAppearance protocol更改导航标题的字体,代码如下:
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"Helvetica-Bold" size:18] forKey:UITextAttributeFont];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];发布于 2013-04-04 18:58:07
由于使用了iOS5,您可以像这样使用新的titleTextAttributes属性:
NSMutableDictionary *newAttributes = [[NSMutableDictionary alloc] init];
[newAttributes setObject:[UIFont boldSystemFontOfSize:18] forKey:UITextAttributeFont];
[self.navigationController.navigationBar setTitleTextAttributes:newAttributes];可能的关键字包括:
UITextAttributeFont
UITextAttributeTextColor
UITextAttributeTextShadowColor
UITextAttributeTextShadowOffsethttps://stackoverflow.com/questions/2771541
复制相似问题