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


当前回答

斯威夫特5。

uiButton.titleLabel?.font = UIFont.systemFont(ofSize: 32)

其他回答

button.titleLabel.font = <whatever font you want>

对于那些想知道为什么他们的短信不显示的人,如果你这样做了

button.titleLabel.text = @"something";

它不会显示,你需要做:

[button setTitle:@"My title" forState:UIControlStateNormal]; //or whatever you want the control state to be

objective - c:

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

迅速:

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

只会改变字体大小。

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

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

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

希望对你有所帮助

[_button.titleLabel setFont:[UIFont systemFontOfSize:15]];  

祝你好运

button.titleLabel.font = [UIFont systemFontOfSize:size];

应该帮助