Custom UITableViewCell with Partially Bold Text

筅森魡賤 提交于 2019-12-06 03:30:04

I wonder if you should subclass UILabel and do the drawing yourself. Then you could use CGContextSelectFont, CGContextGetTextPosition, CGContextSetTextPosition, CGContextShowText etc to draw your text.

Select the normal font, set the initial text position, draw your text, advance the text position by a few pixels, select the bold font, draw your bold text, and so on.

I haven't done this myself before, but am thinking of using this solution for one of my applications as well.

Andy Shea

It looks like this has been asked a few times on Stack Overflow under various guises. A common solution seems to be the Three20 library's TTStyledTextLabel. Until the iPhone SDK includes an inbuilt rich text label and short of rolling my own, this class looks to be the next best thing.

Edit: Just came across this solution and it looks even better: https://github.com/chrisdevereux/Slash

enter code here  NSDictionary  *firstNameAttributes = @{ NSFontAttributeName : [UIFont fontWithName:@"Arial" size:20.0],
                                            NSStrokeColorAttributeName : [UIColor blackColor]};
    NSDictionary  *lastNameAttributes = @{NSFontAttributeName : [UIFont fontWithName:@"Arial-Bold" size:20.0],
                                          NSStrokeColorAttributeName : [UIColor blackColor]};
    NSString* first = @"udhaya";
    NSString* last = @" chandrika";


    NSString *append=[NSString stringWithFormat:@"%@%@",first,last];

    cell.textLabel.text = [NSString stringWithFormat:@"%@",append];

    NSMutableAttributedString * name =
    [[NSMutableAttributedString alloc] initWithString:first attributes:firstNameAttributes];
    NSMutableAttributedString * lastName =
    [[NSMutableAttributedString alloc] initWithString:last attributes:lastNameAttributes];

    [name appendAttributedString:lastName];

    [[cell textLabel] setAttributedText:name];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!