简体   繁体   中英

NavigationBar's title showing only the half-top

To make a long story short, that's what I get:

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

Here is some code from my 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];

What can possibly be the problem ?

I've had similar problems and sorted them out by using something like this:

- (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;
}

You will need to tweek this a bit to get it to work with your font. Hopefully it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM