【问题标题】:Is it possible to change the size of a navigation bar text是否可以更改导航栏文本的大小
【发布时间】:2014-06-02 10:38:52
【问题描述】:

我的 IOS 应用上有一个导航栏。我正在尝试更改 IPAD 的导航栏文本,但是虽然我可以更改导航栏字体,但我无法更改字体大小。请有人可以让我知道我哪里出错了。请在下面找到代码:

if ([self isIPAD ])
{
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil, [UIFont fontWithName:@"Helvetica" size:28], NSFontAttributeName, nil];
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];
}
else
{
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];
}

【问题讨论】:

  • 只需删除 attritube 中用于 ipad 条件的额外“nil”。它是 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, **nil**(去掉这个), [UIFont fontWithName:@"Helvetica" size:28], NSFontAttributeName, nil];

标签: objective-c ios7 uinavigationbar


【解决方案1】:

字体的大小可以调整。你有一个错字。您必须删除字典中间的 nil 。

我建议您使用 objC 文字语法来更早地“捕获”这些错误。这种语法要严格得多:

NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:28]};

(请注意,条形的大小是硬编码的,因此您的字体不能无限增长。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多