user1208852
user1208852

Reputation:

How to create a bold and normal font text in single UILabel in iPhone?

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?

Upvotes: 9

Views: 5851

Answers (3)

Khalid Usman
Khalid Usman

Reputation: 1282

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

Upvotes: 5

picknick
picknick

Reputation: 4007

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.

Upvotes: 1

Vignesh
Vignesh

Reputation: 10251

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

Upvotes: 0

Related Questions