Несколько цветов в UITableViewCell - PullRequest
0 голосов
/ 18 декабря 2011

Учитывая следующий код UITableViewCell, как мы можем сделать myObj.firstName красным и myObj.lastName зеленым?

UITableViewCell *cell;
....
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@", myObj.firstName, myObj.lastName];

Ответы [ 3 ]

1 голос
/ 18 декабря 2011

Вы можете попытаться установить для cell.textlabel экземпляр OHAttributedLabel.

OHAttributeLabel @ GitHub

0 голосов
/ 24 декабря 2011

Возможно, это может помочь другим, я решил это с ...

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tv dequeueReusableCellWithIdentifier:@"Cell"];

    ...

    // Get the size of UILabel firstName.
    CGSize size = [[cell.firstName text] sizeWithFont:[cell.firstName font]];

    // Draw UILabel lastName next to UILabel firstName.
    // UILabel firstName was initialized in CustomCell.m in -(void)layoutSubviews.
    cell.lastName.frame = CGRectMake(size.width + 50, 23, 40, 15);

    // Make lastName green, oh yeah!
    cell.lastName.textColor = [UIColor colorWithRed:0 green:0.6 blue:0 alpha:1];
}
0 голосов
/ 18 декабря 2011

Вам потребуется два экземпляра UILabel для достижения этой цели, потому что UILabel не поддерживает рисование экземпляров NSAttributedString. Вы также можете создать подкласс UITableViewCell, переопределить drawRect: и нарисовать текст вручную требуемыми цветами с помощью методов -drawTextAtPoint: в NSString.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...