问题
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]];

回答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];
回答2:
Probably you can get the UIAppearance for UILabel inside UINavigationBar.
来源:https://stackoverflow.com/questions/7779190/using-uiappearance-to-change-label-height