ios - 导航栏标题仅显示半顶

标签 ios objective-c navigationbar

长话短说,这就是我得到的:

http://img839.imageshack.us/img839/9461/capturedcran20130418000x.png

这是我的 AppDelegate 中的一些代码:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"main_bar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  //[UIColor colorWithRed:125.0/255.0 green:111.0/255.0 blue:100.0/255.0 alpha:1.0],
  //UITextAttributeTextColor,
  //[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
  //UITextAttributeTextShadowColor,
  //[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
  //UITextAttributeTextShadowOffset,
  [UIFont fontWithName:@"Pacifico" size:25],
  UITextAttributeFont,
  nil]];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-10 forBarMetrics:UIBarMetricsDefault];

可能是什么问题?

最佳答案

我也遇到过类似的问题,并通过使用类似的方法解决了它们:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Home";
        self.tabBarItem.image = [UIImage imageNamed:@"main_bar.png"];
        CGRect frame = CGRectMake(0, 0, 400, 44);
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:20.0];
        label.shadowColor = [UIFont fontWithName:@"Pacifico" size:25];
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        self.navigationItem.titleView = label;
        label.text = NSLocalizedString(@"Remindbox", @"");
    }
    return self;
}

您需要对此进行一些调整才能使其与您的字体一起使用。希望它能有所帮助。

关于ios - 导航栏标题仅显示半顶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16071156/

相关文章:

ios - 从行中的单个项目隐藏 View (collectionViewCell 项目)

ios - 无法在 iOS 12.4.1 (iPhone XR) 中使用 CNContactStore 获取联系人。即使在 13 beta 或 12.4.1 以下也能正常工作

objective-c - 运行同一个 XPC 服务的多个实例 (NSXPCConnection)

jquery - 粘性导航栏跳到顶部

ios - 栏按钮在运行时未显示在导航栏上

android - Flutter multi_image_picker相机选项未在iOS中显示。当我已经启用摄像头并将权限写入info.plist中时

ios - 适用于 iOS 的 Xcode 本地化 - 法语 (fr) 和法语比利时 (fr-BE) 之间的区别

ios - UICollectionView 不显示任何图像

iphone - AVAssetWriter 不适用于音频

html/css 垂直导航栏