9

I want to create like following Sample text in UILabel..

Muthu: Hi I am on the way to office..
wait for the few mins...

This type of text have UITableviewCustom cell have the UILabel.

How to create in the UILabel?

Jason Sturges
  • 15,855
  • 14
  • 59
  • 80

3 Answers3

5

Use the following code and include the .h and .m files from the following link "https://github.com/AliSoftware/OHAttributedLabel".

-(void)addTitleView{

    NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Muthu: Hi I am on the way to office..wait for the few mins..."];
    [attrStr setFont:[UIFont fontWithName:@"Verdana" size:16]];
    [attrStr setTextColor:[UIColor whiteColor]];
    [attrStr setFont:[UIFont fontWithName:@"Verdana-Bold" size:16] range:NSMakeRange(0,6)];
    
    OHAttributedLabel *titleLabel = [[OHAttributedLabel alloc] init];
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [titleLabel setFrame:CGRectMake(0, 0, 200, 35)];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    titleLabel.adjustsFontSizeToFitWidth = YES;
    titleLabel.attributedText = attrStr;
    titleLabel.textAlignment = UITextAlignmentJustify;
    [self.view addSubview:titleLabel];
}
Khalid Usman
  • 1,272
  • 1
  • 13
  • 32
1

Use UILabels with support for attributed strings is TTTAtributedLabel or OHAttributedLabel

I use OHAttributedLabel. Refer to this ansewr for an example and use setTextBold for boldness.

Community
  • 1
  • 1
picknick
  • 3,897
  • 6
  • 33
  • 48
0

You got to use NSAttributedString. There are many open source components available to do that for you. Have a look at this.

Community
  • 1
  • 1
Vignesh
  • 10,205
  • 2
  • 35
  • 73