2

Is there any way to use UIAppearance to change the height of a label inside of a UINavigationBar. Here's the code and an image of what's going on so you can understand what the problem is.

[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-5.0 forBarMetrics:UIBarMetricsLandscapePhone];

NSDictionary *textAttributes =  [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIFont fontWithName:@"MarketingScript" size:34.0], nil] 
                                                            forKeys:[NSArray arrayWithObjects:UITextAttributeFont, nil]];

enter image description here

hypercrypt
  • 15,389
  • 6
  • 48
  • 59
Travis
  • 5,021
  • 2
  • 28
  • 37

2 Answers2

1

I ended up solving this by creating a custom UIView:

+(NavigationBarTitleLabel *)titleLabelWithTitle:(NSString *)title {
  // this will appear as the title in the navigation bar
  NavigationBarTitleLabel *labelWrapper = [[NavigationBarTitleLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 34)];
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, 200, 32)];

  label.font            = [UIFont fontWithName:@"MarketingScript" size:28.0];
  label.text            = title;
  label.textColor       = XHEXCOLOR(0XFFFFFF);
  label.textAlignment   = UITextAlignmentCenter;
  label.backgroundColor = [UIColor clearColor];
  label.layer.shadowColor = [UIColor blackColor].CGColor;
  label.layer.shadowRadius = 2;
  [labelWrapper addSubview:label];
  [labelWrapper sizeToFit];

  return labelWrapper;
}

and then setting the titleView property on the navigationItem:

self.navigationItem.titleView = [NavigationBarTitleLabel titleLabelWithTitle:self.title];
Travis
  • 5,021
  • 2
  • 28
  • 37
  • What is the advantage of using a custom view in this case if you're just adding a UILabel to it? Why not make it a simple UIView? – Andrew T. Jul 06 '12 at 14:37
0

Probably you can get the UIAppearance for UILabel inside UINavigationBar.

Sulthan
  • 128,090
  • 22
  • 218
  • 270