一行文字 要显示成 一行文字
不需要用不同的两个Label进行拼接 今儿个就放个方法进来
UILabel * o_priceLabel = [[UILabel alloc]init];
o_priceLabel.text = @"一行文字";
o_priceLabel.textAlignment = NSTextAlignmentRight;
o_priceLabel.textColor = [UIColor redColor];
o_priceLabel.font = [UIFont systemFontOfSize:17];
[cell.contentView addSubview:o_priceLabel];
NSRange newO_priceRange = NSMakeRange(0,2);
NSMutableAttributedString * pricestr = [[NSMutableAttributedString alloc]initWithString:@"<span style="font-family: Arial, Helvetica, sans-serif;">一行文字</span><span style="font-family: Arial, Helvetica, sans-serif;">"];</span>
[pricestr addAttributes: @{NSForegroundColorAttributeName:[UIColor grayColor],NSFontAttributeName:[UIFont systemFontOfSize:12]} range:newO_priceRange];
[o_priceLabel setText:@"一行文字"];
[o_priceLabel setAttributedText:pricestr];
本文介绍了一种使用UILabel显示不同样式文本的方法,通过NSAttributedString可以实现在同一个UILabel中展示不同颜色及大小的文字,避免了使用多个Label进行拼接的情况。
426

被折叠的 条评论
为什么被折叠?



