开发者

Custom font title for UIButton

Is there a way to have custom fonts to the title of开发者_JAVA技巧 a button.


The UIButton class exposes a titleLabel property, upon which you can change things like the font, the text color, etc.


Set the font of the button's titleLabel:

myButton.titleLabel.font = [UIFont fontWithName:@"Courier" size:22.0];


You can always render text in a UIImage and then configure the button to use that with setImage:forState:. This allows you to do custom fonts, labels with icons, images, etc.


In case you want to list all available fonts and then select your font, run this Swift code:

UIFont.familyNames().forEach {
    print($0)
    UIFont.fontNamesForFamilyName($0).forEach {
        print("  \($0)")
    }
}

It prints all font names for their font families. Then assign the same font name as printed.

button.titleLabel.font = UIFont(name: "OpenSans", size: 20.0)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜