我的应用程序有一个顶部有导航控制器的视图控制器。导航栏标题为“忘记密码”。这个标题在iOS 5和6中没有任何换行符显示。但是当我在iOS 7中运行相同的应用程序时,导航栏标题在末尾显示为点 - “Forgot Passw ...”纠正此缺陷的唯一方法是减少导航栏标题的大小。
有人能告诉我该怎么办? iOS 7中是否有专门用于此目的的API。是否可以单独减少此视图控制器的导航栏标题的字体大小?欢迎大家提出意见。提前致谢。
答案 0 :(得分:7)
UILabel *nav_titlelbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.navigationItem.titleView.frame.size.width,40)];
nav_titlelbl.text=@"Tests";
nav_titlelbl.textAlignment=NSTextAlignmentCenter;
UIFont *lblfont=[UIFont fontWithName:@"FontinSansCR-Bold" size:20];
[nav_titlelbl setFont:lblfont];
self.navigationItem.titleView=nav_titlelbl;
答案 1 :(得分:2)
我在项目中使用了以下代码,并为我工作:
/* ios 7 Change */
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//self.edgesForExtendedLayout = UIRectEdgeNone;
//self.automaticallyAdjustsScrollViewInsets = NO;
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x4B678B)];
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:@"Helvetica Neue" size:21.0], NSFontAttributeName, nil]];
// self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
//[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
答案 2 :(得分:1)
以下是我在自己的项目中使用的代码(iOS 7)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// set the title text property, color, font, size and so on
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 WhiteColor],NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"your font" size:21.0], NSFontAttributeName, nil]];
return YES;
}
答案 3 :(得分:0)
从iOS7开始,我总是这样做:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica-Bold" size:SIZE_YOU_LIKE],NSFontAttributeName,
nil]];
关键字UITextAttributeFont
已经从iOS7中沮丧,你应该替换为
NSFontAttributeName
。
只需设置SIZE_YOU_LIKE
您喜欢的值〜