ios - 使用 TitleView 在 IOS 的导航栏上添加 2 行文本

标签 ios uinavigationbar titleview

我必须使用标题 View 在导航栏上添加两行不同字体大小的文本。

我试过下面的代码:

我想要大字体的 EREDITOMETRO 和小字体的 LA SUCCESSIONE A PORTATA DI MANO

UILabel * label =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)]; label.backgroundColor =[UIColor clearColor]; 
label.numberOfLines =2; 
label.font =[UIFont boldSystemFontOfSize:9.0f];
label.textColor =[UIColor whiteColor]; 
label.text = @"EREDITOMETRO \n LA SUCCESSIONE A PORTATA DI MANO"; 

self.navigationItem.titleView = label;

最佳答案

试试这个 -

NSString *stringName = @"Welcome Home" ;
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:stringName];
[attrString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize: 14.0f] range:NSMakeRange(0, 4)];

UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.numberOfLines =0;
label.attributedText = attrString;
self.navigationItem.titleView = label;

关于ios - 使用 TitleView 在 IOS 的导航栏上添加 2 行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29469715/

相关文章:

iphone - 自定义背景不在 View 更改时设置动画

ios - 在 Swift 中以编程方式定位对象

ios - CABasicAnimation - 变换比例保持在中心

iphone - 获取 navigationItem.titleView layoutSubviews 的正确边界

iphone - 导航栏中标题的默认字体大小、字体名称和阴影是多少?

ios - 如何在长按 UITableViewCell 时 swift 调用另一个 Controller ?

ios - 在 viewDidLoad 期间设置的导航栏按钮在 iOS 11 中出现 View 之后才会出现

ios - setNavigationBarHidden 在 setViewControllers 之后不起作用

ios - 导航 Controller 将 Storyboard中的所有 View 向下移动 64 像素,尽管它被隐藏了。

iphone - UINavigationItem.titleView可以成为FirstResponder吗?