gpt4 book ai didi

ios - 导航栏标题对齐

转载 作者:行者123 更新时间:2023-11-29 12:01:24 25 4
gpt4 key购买 nike

enter image description here

[[UIBarButtonItem appearance] 

setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:RED_COLOR ,NSFontAttributeName:[UIFont fontWithName:@"OpenSans-Semibold" size:16]}];
self.navigationItem.title=@"ORDER DETAILS";

我正在使用上面的代码为 View Controller 设置标题,但标题显示不正确。在某些 View Controller 中,它会按预期出现

最佳答案

  // here to create a UILabel

UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.numberOfLines = 1;
// set your custom font for title

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"ORDER DETAILS"];
[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0,5)];

// set line spacing
NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineSpacing:6];
[paragrahStyle setAlignment:NSTextAlignmentCenter];
[string addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [string length])];

label.attributedText = string;
[label sizeToFit];
self.navigationItem.titleView = label;

复制自:Navigationbar title alignment issue

否则更好的想法是将标题作为 UiImage,您可以将该图像用作导航栏标题。使用具有 2x 和 3x 版本的适当大小的 44x44 pt 图像。

UIImageView* titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Orderpng.png"]];
imageView.contentMode = UIViewContentModeScaleAspectFit;

UIView* titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
imageView.frame = titleView.bounds;
[titleView addSubview:imageView];

self.navigationItem.titleView = titleView;

享受编码:)

关于ios - 导航栏标题对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36857525/

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