label.font.pointSize是只读的,所以我不确定如何更改它。


当前回答

你可以使用分机。

import UIKit

extension UILabel {

    func sizeFont(_ size: CGFloat) {
        self.font = self.font.withSize(size)
    }
}

使用它:

self.myLabel.fontSize(100)

其他回答

在Swift 3中:

label = UIFont.systemFont(ofSize: 20)

并使用系统预设的大小,例如:

label = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)

从故事板中更改字体大小非常简单和方便,您可以立即看到更改的结果。

实际上,改变storyboard上的其他字体属性也很容易,比如样式、字体族等。

在swift3, 假设你的可用名称是myLable,你想改变它的字体大小 这样做

myLable.font = UIFont.systemFont(ofSize: 10)

你也可以这样给予

labelName.font = UIFont(name: "systemFont", size: 30)

再次在Swift 3中…

myLabel.font = myLabel.font.withSize(18)