设置UIButton文字大小颜色不同

_loginBtn = [[UIButton alloc]initWithFrame:CGRectMake(iconX, CGRectGetMaxY(passwordBGView.frame)+25, 280, 35)];
[_loginBtn setTitle:@"进入游戏\nSTART 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;

 

posted @ 2015-04-05 19:21  嗷大喵  阅读(1629)  评论(0编辑  收藏  举报