-5

-で構成される文字列があります

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 %%」はBoldenでしたか?よろしくお願いします

4

4 に答える 4

6

おそらくこれはあなたを助けることができます

単一のUILabelの太字と非太字のテキスト?

iOS 6向けのソリューションがあり、iOS5向けにはNSAttributedStringでCATextLayerを使用する必要があります

または、http://www.cocoacontrols.com/platforms/ios/controls/ohattributedlabelを参照することもできます

https://github.com/AliSoftware/OHAttributedLabel/

https://github.com/mattt/TTTAttributedLabel/

于 2012-12-28T11:56:54.147 に答える
4

Helvetica太字のような必要なフォント名

lblWithText.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0];

単なる例..

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];

これはあなたを通してアイデアを得る例です..

アップデート:

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;
于 2012-12-28T11:42:41.987 に答える
1

完全に太字の場合は、これを試すことができます

[lblWithText setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12.f]]

さまざまなフォントについても、このリンクにアクセスしてください

ある部分を通常の太字にしたいということですが、attributedStringを試すことはできますが、確かではありません。

または、このリンクこれにアクセスしてください。

于 2012-12-28T11:51:58.683 に答える
1

これにはNSMutableAttributedStringを使用してください。NSMutableAttributedStringについてはこのtutorailに従ってください。

http://soulwithmobiletechnology.blogspot.in/2012/07/how-to-use-nsattributedstring-in-ios-6.html

于 2012-12-28T11:56:27.740 に答える