0

我的应用程序有一个视图控制器,顶部有一个导航控制器。导航栏标题为“忘记密码”。此标题在 iOS 5 和 6 中显示时没有任何换行符。但是,当我在 iOS 7 中运行相同的应用程序时,导航栏标题显示在末尾带有点 - '忘记密码...' 纠正此缺陷的唯一方法是减小导航栏标题的大小。

有人可以告诉我我该怎么做吗?iOS 7 中是否有专门用于此目的的 API。是否可以单独减小此视图控制器的导航栏标题的字体大小?欢迎大家提出意见。提前致谢。

4

4 回答 4

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;
于 2013-10-06T04:26:24.180 回答
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]];

    }
于 2013-10-18T13:29:28.287 回答
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;
}
于 2013-10-18T13:16:56.023 回答
0

自iOS7以来,我总是喜欢以下内容:

[[UINavigationBar appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
        [UIFont fontWithName:@"Helvetica-Bold" size:SIZE_YOU_LIKE],NSFontAttributeName,
        nil]];

从 iOS7 开始,该关键字UITextAttributeFont已被抑制,您应该替换为 NSFontAttributeName.

只要设置SIZE_YOU_LIKE一个你喜欢的值~

于 2014-11-08T06:18:15.767 回答