-5

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

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

John Parker
  • 54,048
  • 11
  • 129
  • 129

4 Answers4

6

Probably this can help you

Bold & Non-Bold Text In A Single UILabel?

it has solution for iOS 6 and for iOS5 you will have to use a CATextLayer with an NSAttributedString

or you may refer to http://www.cocoacontrols.com/platforms/ios/controls/ohattributedlabel

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

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

Community
  • 1
  • 1
HarshIT
  • 4,583
  • 2
  • 30
  • 60
4

just required Helvetica font name with Bold like

lblWithText.font = [UIFont fontWithName:@"Helvetica-Bold" size: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 ..

UPDATE:

Also See this Example with 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;
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
1

For full bold you can try with this

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

Also go to this link for various fonts

As you said you want some part as bold some normal, then you can try attributedString, but not sure.

Or go to this link and this.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
1

Use NSMutableAttributedString for this please follow this tutorail for NSMutableAttributedString

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

Sumit Mundra
  • 3,891
  • 16
  • 29