UIButton *valueBtn=[UIButton buttonWithType:UIButtonTypeCustom];
valueBtn.frame=CGRectMake(100, 100, 200, 40);
NSMutableAttributedString *str=[[NSMutableAttributedString alloc]initWithString:@"昨日产值: 5L鲜奶"];//有空格
NSRange range=NSMakeRange(0, [str length]);
//设置前半部分字体颜色
[str addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, 5)];
//设置前半部分字体大小
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0f] range:NSMakeRange(0, 5)];
//设置后半部分字体颜色
[str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:244/255.0f green:93/255.0f blue:97/255.0f alpha:1.0] range:NSMakeRange(5, 5)];
//设置后半字体大小
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0f] range:NSMakeRange(5, 5)];
//添加下划线
[str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:range];
[valueBtn setAttributedTitle:str forState:UIControlStateNormal];
[self.view addSubview:valueBtn];
#warning :1.关键字 NSMutableAttributedString
2.注意 NSMakeRange(a,b)中 ,参数1:是起始点位置下标 参数2:长度
3.前面属性带AttributeName