本文介绍了如何在标签内的单个字符串上使用多种字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串 - -

I have a string consisting of -

lblWithText.backgroundColor = [UIColor clearColor];
    lblWithText.textColor = [UIColor blackColor];
    lblWithText.font = [UIFont fontWithName:@"Helvetica" size:12.0];
    lblWithText.text = [NSString stringWithFormat:@"Blah1:blah-blah%d. Blah2:-%d%%", [currentCoupon.couponPrice intValue],[currentCoupon.couponDiscountPercent intValue]];

请告诉我怎么做Blah2: - %d %%是博尔登?
提前感谢

Please tell me how to do that would be "Blah2:-%d%%"" was Bolden?thanks in advance

推荐答案

只需要 Helvetica 字体粗体名称

lblWithText.font = [UIFont fontWithName:@Helvetica-Bold尺寸:12.0];

只是一个例子......

Just An Example ..

UILable *lbl1 = [[UILable alloc]init];
lbl1.frame = CGRectMake(10,10,100,40);
lbl1.backgroundColor = [UIColor clearColor];
lbl1.textColor = [UIColor blackColor];
lbl1.font = [UIFont fontWithName:@"Helvetica" size:12.0];
lbl1.text = @"Stack";

UILable *lbl2 = [[UILable alloc]init];
lbl2.frame = CGRectMake(110,10,150,40);
lbl2.backgroundColor = [UIColor clearColor];
lbl2.textColor = [UIColor blackColor];
lbl2.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0];
lbl2.text = @"OverFlow";

[self.view addSubview:lbl1];
[self.view addSubview:lbl2];

这是一个通过你的想法得到的例子..

this is an example which through you get idea ..

更新:

另请参阅NSMutableAttributedString示例:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Blah1:blah-blah%d. Blah2:-%d%%", [currentCoupon.couponPrice intValue],[currentCoupon.couponDiscountPercent intValue]];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(0,30)];/// Define Range here and also BackGround color which you want
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,30)];/// Define Range here and also TextColor color which you want
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];
lblWithText.attributedText = str;

这篇关于如何在标签内的单个字符串上使用多种字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:02