gpt4 book ai didi

iphone - 使用 UIAppearance 改变标签高度

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:55:15 28 4
gpt4 key购买 nike

有什么方法可以使用 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]];

enter image description here

最佳答案

我最终通过创建自定义 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];

关于iphone - 使用 UIAppearance 改变标签高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7779190/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com