//button设置下划线
NSMutableAttributedString *str =[[NSMutableAttributedString alloc] initWithString:@"月利宝产品详情"];
[str addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:(NSRange){0,[str length]}]; //下划线样式
[str addAttribute:NSUnderlineColorAttributeName value:[UIColor redColor] range:(NSRange){0,[str length]}]; //下划线颜色
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:(NSRange){0,[str length]}]; //字体颜色
[self.detailBtn setAttributedTitle:str forState:(UIControlStateNormal)];
// 效果
// 一段文字显示不同的颜色和字体
UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 320, 30)];
testLabel.backgroundColor = [UIColor lightGrayColor];
testLabel.textAlignment = NSTextAlignmentCenter;
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"今天天气不错呀"];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:16.0]
range:NSMakeRange(2, 2)];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(2, 2)];
testLabel.attributedText = AttributedStr;
[self.view addSubview:testLabel];
// 效果