属性字符串的使用:
if(!_pwdButton) {
_pwdButton = [UIButton buttonWithType:UIButtonTypeSystem];
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//设置下划线的颜色
dic[NSUnderlineColorAttributeName] = [UIColor orangeColor];
//设置下划线可见
dic[NSUnderlineStyleAttributeName] = @YES;
//设置字体
dic[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//设置字体颜色
dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
NSAttributedString *title = [[NSAttributedString alloc]initWithString:@"密码登录" attributes:dic];
[_pwdButton setAttributedTitle:title forState:UIControlStateNormal];
[self.view addSubview:_pwdButton];
[_pwdButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(100);
make.centerX.equalTo(0);
make.height.equalTo(50);
make.width.equalTo(100);
}];
// [_pwdButton setAttributedTitle:title forState:UIControlStateNormal];
// [self.view addSubview:_pwdButton];
// [_pwdButton mas_makeConstraints:^(MASConstraintMaker *make) {
// make.right.equalTo(-25);
// make.top.equalTo(self.codeLoginButton.mas_bottom).offset(15);
// }];
}
return _pwdButton;
}
效果如下图: