如何在iPhone中的单个UILabel中创建粗体和普通字体文本?

9 iphone ios4 ios ios5

我想在UILabel中创建以下示例文本.

Muthu:嗨,我正在去办公室的路上......
等几分钟......

这种类型的文本有UITableviewCustom单元格有UILabel.

如何在UILabel中创建?

Kha*_*man 5

使用以下代码并包含以下链接"https://github.com/AliSoftware/OHAttributedLabel"中的.h和.m文件.

-(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];
}
Run Code Online (Sandbox Code Playgroud)