我需要通过编程方式设置UIButton标题UILabel的字体大小。


当前回答

【按钮setFont:……已被弃用。

使用[按钮。titleLabel setFont:…而是,例如:

[myButton.titleLabel setFont:[UIFont systemFontOfSize:10]];

其他回答

斯威夫特4

button.titleLabel?.font = UIFont(name: "Font_Name_Here", size: Font_Size_Here)

objective - c

[button.titleLabel setFont:[UIFont fontWithName:@“Font_Name_Here” size: Font_Size_Here]];

例子:

Font_Name = "Helvetica"

Font_Size = 16.0

希望能有所帮助。

【按钮setFont:……已被弃用。

使用[按钮。titleLabel setFont:…而是,例如:

[myButton.titleLabel setFont:[UIFont systemFontOfSize:10]];

objective - c:

[button.titleLabel setFont: [button.titleLabel.font fontWithSize: sizeYouWant]];

迅速:

button.titleLabel?.font = button.titleLabel?.font.fontWithSize(sizeYouWant)

只会改变字体大小。

您还可以自定义按钮字体粗体,斜体。 本例采用系统粗体字体大小。

[LoginButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f*Ratio]];

这会很有帮助

button.titleLabel.font = [UIFont fontWithName:@"YOUR FONTNAME" size:12.0f]