同一字符串不同颜色不同大小

/*新建*/

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"你还没有自己的群组,快去新建吧!"];

[string addAttribute:NSForegroundColorAttributeName value:[HqewUtil colorWithHexString:@"#999999"] range:NSMakeRange(0,12)];

[string addAttribute:NSForegroundColorAttributeName value:[HqewUtil colorWithHexString:@"#50acee"] range:NSMakeRange(12,2)];

[string addAttribute:NSForegroundColorAttributeName value:[HqewUtil colorWithHexString:@"#999999"] range:NSMakeRange(14,2)];

UITextField *newGroupLabel=[[UITextField alloc]initWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, 56)];

newGroupLabel.delegate=self;

newGroupLabel.attributedText=string;

newGroupLabel.textAlignment=NSTextAlignmentCenter;

newGroupLabel.font=[UIFont systemFontOfSize:14];

//    [headView addSubview:newGroupLabel];




2.


-(void)initWithUploadMemberControls

{

UILabel *tipLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT*0.15 + SCREEN_WIDTH - 2 * SCREEN_WIDTH*0.15+60, SCREEN_WIDTH, 100)];

tipLabel.numberOfLines=4;

tipLabel.font=[UIFont systemFontOfSize:14];

tipLabel.textColor=[UIColor whiteColor];

tipLabel.textAlignment=NSTextAlignmentCenter;

//    tipLabel.text=[NSString stringWithFormat:@"在电脑浏览器打开\n%@\n并扫描页面中的二维码登录\n网页版导入会员表格",@"https://www.baidu.com"];

NSString *urlString=@"https://www.baidu.com";

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"在电脑浏览器打开\n%@\n并扫描页面中的二维码登录\n网页版导入会员表格",urlString]];

[str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,8)];

[str addAttribute:NSForegroundColorAttributeName value:[HqewUtil colorWithHexString:@"#50acee"] range:NSMakeRange(9,urlString.length)];

[str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(9+urlString.length+1,21)];

tipLabel.attributedText = str;

[self.view addSubview:tipLabel];

}




http://www.jianshu.com/p/108bcc5f0472




你可能感兴趣的:(同一字符串不同颜色不同大小)