[iOS] 修改 tabbar 字体样式

Objective-C版本

如果是使用ObjectiveC来开发,那么可以这么全局修改:

NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:0.5]};
[[UIBarButtonItem appearance]setTitleTextAttributes:attributes
forState:UIControlStateNormal];
如果是修改单个UIBarButtonItem对象,可以直接设置:

[itemsetTitleTextAttributes:attributesforState:UIControlStateNormal];
[itemsetTitleTextAttributes:attributesHighlightedforState:UIControlStateSelected];

其中item是UIBarButtonitem对象。

Swift版本

对于Swift版本,其实也是一样的,这种方式是全局的设置方法:

// 这里样式要改成什么样,自己需要的
letnormalAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)]
let highlightedAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)];
UIBarButtonItem.appearance().setTitleTextAttributes(normalAttributes, forState: .Normal)
UIBarButtonItem.appearance().setTitleTextAttributes(highlightedAttributes, forState: .Normal)

如果只是想对单个设置样式,可以这样:

letnormalAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)]
let highlightedAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)];

item.setTitleTextAttributes(normalAttributes, forState: .Normal)
item.setTitleTextAttributes(highlightedAttributes, forState: .Normal)

其中,item是UIBarButtonItem对象。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容