设置UIButton文字大小颜色不同

_loginBtn = [[UIButton alloc]initWithFrame:CGRectMake(iconX, CGRectGetMaxY(passwordBGView.frame)+25, 280, 35)];
[_loginBtn setTitle:@"进入游戏
START GAME" forState:UIControlStateNormal];
_loginBtn.titleLabel.font = [UIFont systemFontOfSize:16];
         
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:_loginBtn.titleLabel.text];
[attString addAttribute:(NSString*)NSForegroundColorAttributeName value:[UIColor whiteColor] range:[_loginBtn.titleLabel.text rangeOfString:_loginBtn.titleLabel.text]];
[attString addAttribute:(NSString*)NSForegroundColorAttributeName value:[UIColor whiteColor] range:[_loginBtn.titleLabel.text rangeOfString:@"START GAME"]];
[attString addAttribute:(NSString*)NSFontAttributeName value:[UIFont systemFontOfSize:10] range:[_loginBtn.titleLabel.text rangeOfString:@"START GAME"]];
[_loginBtn setAttributedTitle:attString forState:UIControlStateNormal];
         
_loginBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
_loginBtn.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;

 

原文地址:https://www.cnblogs.com/damiao/p/4394563.html