设置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;

时间: 2024-08-02 13:40:31

设置UIButton文字大小颜色不同的相关文章

代码设置UIButton文字、图片位置

假设有按钮rButton的 imageEdgeInsets和contentEdgeInsets可以设置按钮的标题和图片的位置,如下代码,设置标题居右 NSString * rBtnTitle = @"删除"; CGSize size = [rBtnTitle sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}]; NSLog(@"size = %@",NSStringFromC

自定义导航条 文字大小颜色等 按钮大小图标等 背景色

UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [leftBtn setTitleColor:lightBlue forState:UIControlStateNormal]; leftBtn.backgroundColor = [UIColor clearColor]; leftBtn.frame = CGRectMake(0, 0, 60, 44); [leftBtn addTarget:self actio

UIAlertController 标题文字大小 颜色

NSString *title = [NSString stringWithFormat:@"\n恭喜您获得%d个红包\n", 10]; NSString *msg = @"\n把红包分享给微信好友,金额随机,可用于购买雪票和雪卡"; UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertContr

input 框设置placeholder文字的颜色

input::-webkit-input-placeholder{ color:#999999; } input::-moz-placeholder{ /* Mozilla Firefox 19+ */ color:#999999; } input:-moz-placeholder{ /* Mozilla Firefox 4 to 18 */ color:#999999; } input:-ms-input-placeholder{ /* Internet Explorer 10-11 */ c

Android TextView设置多彩文字

在应用开发中时常会遇到需要在一段文字中插入几个不一样颜色文字的需求; 以前本人都是用多个TextView拼起来,不仅感觉很蠢,操作起来也蛮恶心; 直到接触到了SpannableStringBuilder,感觉整个人都好了; 在我搭建界面布局,会有一些带String占位符的默认文字,如:"现在的气温是:%s","今天天气:%1$s,最高气温:%2$s,最低气温:%3$s,降雨率:%4$s,pm2.5:%5$s."; 之后在获取到数据时,直接String.format(

iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色

btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlStateNormal]; //设置按钮上的自体的大小 //[btn setFont: [UIFont systemFontSize: 14.0]];    //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法 //应该使用 btn.titleLabel.font = [UIFont sys

设置UIButton的文字显示位置、字体的大小、字体的颜色、加粗

btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlStateNormal]; //设置按钮上的自体的大小 //[btn setFont: [UIFont systemFontSize: 14.0]];    //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法 //应该使用 btn.titleLabel.font = [UIFont sys

统一设置UITabBarController管理的所有VC的tabBarItem图标文字的颜色大小等属性

1. 统一设置UITabBarController管理的所有VC的tabBarItem图标文字的颜色大小等属性 //设置字体大小及颜色(可变字典才可用[]方法设值) NSMutableDictionary *attr = [NSMutableDictionary dictionary]; attr[NSFontAttributeName] = [UIFont systemFontOfSize:19]; attr[NSForegroundColorAttributeName] = [UIColor

蜗牛爱课 -- iOS 设置UIButton的字体的大小、显示位置、大小

/设置按钮上的自体的大小 //[btn setFont: [UIFont systemFontSize: 14.0]];    //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法 //应该使用 btn.titleLabel.font = [UIFont systemFontOfSize: 14.0]; btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置,现设为居左,