如何设置tabbar的字体样式呢?下面是记录了曾经写下的一小段代码,希望能帮助到后来的人吧!
如果是使用ObjectiveC来开发,那么可以这么全局修改:
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:0.5]}; [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal]; 如果是修改单个UIBarButtonItem对象,可以直接设置: [item setTitleTextAttributes:attributes forState:UIControlStateNormal]; [item setTitleTextAttributes:attributesHighlighted forState:UIControlStateSelected];
其中item是UIBarButtonitem对象。
对于Swift版本,其实也是一样的,这种方式是全局的设置方法:
// 这里样式要改成什么样,自己需要的 let normalAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)] let highlightedAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)]; UIBarButtonItem.appearance().setTitleTextAttributes(normalAttributes, forState: .Normal) UIBarButtonItem.appearance().setTitleTextAttributes(highlightedAttributes, forState: .Normal)
如果只是想对单个设置样式,可以这样:
let normalAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)] let highlightedAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)]; item.setTitleTextAttributes(normalAttributes, forState: .Normal) item.setTitleTextAttributes(highlightedAttributes, forState: .Normal)
其中,item是UIBarButtonItem对象。
承接:ThinkPHP项目开发、网站项目开发、微信项目开发、微信小程序项目开发、App开发,欢迎联系标哥QQ632840804