UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.font=[UIFont systemFontOfSize:16];
label.backgroundColor = [UIColor whiteColor];
label.textAlignment=UITextAlignmentCenter;
label.text = @"testlabel";
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:label];
NSArray *itemArray = [NSArray arrayWithObjects:buttonItem, nil];
[self.navigationController.toolbar setItems:itemArray animated:YES];
转载于:https://www.cnblogs.com/skyry/archive/2013/04/16/5114608.html
本文介绍了一种在iOS应用中使用UILabel创建自定义导航栏按钮的方法。通过设置UILabel的属性,如字体、背景颜色、对齐方式和文本,然后将其作为UIBarButtonItem的自定义视图,可以轻松地在导航控制器的工具栏上添加带有文本的按钮。
12

被折叠的 条评论
为什么被折叠?



