同一label,不同字体颜色

来源:互联网 发布:10档行情软件 编辑:程序博客网 时间:2024/05/16 19:22
UILabel* noteLabel = [[UILabel alloc] init];    noteLabel.frame = CGRectMake(0, 100, 200, 100);    noteLabel.backgroundColor = [UIColor yellowColor];    noteLabel.textColor = [UIColor blackColor];    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"同一label:不同字体颜色"];    NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@":"].location);    [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];    [noteLabel setAttributedText:noteStr] ;    [noteLabel sizeToFit];    [self.view addSubview:noteLabel];
原创粉丝点击