有没有办法使用 UIAppearance 更改 UINavigationBar 内标签的高度。这是代码和正在发生的情况的图像,以便您可以了解问题所在。
[[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]];
我最终通过创建自定义 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;
}
然后在 navigationItem 上设置 titleView 属性:
self.navigationItem.titleView = [NavigationBarTitleLabel titleLabelWithTitle:self.title];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)