如何使用Swift默认UILabel字体和大小 [英] How to default UILabel Font and Size using Swift
本文介绍了如何使用Swift默认UILabel字体和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现 UISegmentedControl
更改字体和大小如下:
I find UISegmentedControl
change font and size like this :
UISegmentedControl.appearance ()。setTitleTextAttributes(myFontAttribute as [NSObject:AnyObject],forState:.Normal)
但是UILabel没有这个方法
but UILabel have no this method
我想这样做
UILabel.appearance()。setAttributed(myFontAttribute)
我不想在StoryBoard中更改UILabel字体
I don't want to change UILabel font in StoryBoard
我想使用程序这样做(因为我的应用程序已完成,但只有字体应更改为更大和其他字体)
I want to using program to do this (because my app is done, but only font should change to bigger and other font)
我该怎么办?
推荐答案
首先你需要为UILabel添加扩展名:
First you need to add extension to UILabel :
extension UILabel{
var defaultFont: UIFont? {
get { return self.font }
set { self.font = newValue }
}
}
第二次使用外观进行设置:
Second use appearance to set it:
UILabel.appearance().defaultFont = UIFont.systemFont(ofSize: 25)
希望有所帮助。
这篇关于如何使用Swift默认UILabel字体和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文