< 返回首页

标哥的笔记,是记录在日常学习技术和日常开发中那些年遇到过的坑!本站为新站,原"标哥的技术博客"中的文章会慢慢移到本站,欢迎收藏本站!
在使用本站过程中,有任何建议请联系标哥! 另,承接App开发、网站开发和微信小程序开发!欢迎联系我们


iOS修改tabbar字体样式

 作者:标哥    发布日期:2017-01-12 17:23    阅读量:1099次
 

如何设置tabbar的字体样式呢?下面是记录了曾经写下的一小段代码,希望能帮助到后来的人吧!

Objective-C版本

如果是使用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版本

对于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