Set hervorgehobenen text Farbe für UILabel mit NSAttributedString.?

Ich bin mit einem Etikett auf tableview cell. Die Zelle zugewiesen worden ist, zugeschrieben string, aber das problem ist, dass bei Auswahl der Zelle und der text nicht weiß, für zugeschrieben string.

Gibt es eine Möglichkeit, es zu beheben..?

Jede Hilfe ist willkommen.

Ist hier ein Blick auf meinen code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    LHSearchViewCell *cell = [LHSearchViewCell cellForTableView:tableView fromNib:_cellNib];

    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    cell.headerLabel.textColor = [UIColor darkGrayColor];
    cell.headerLabel.highlightedTextColor = [UIColor whiteColor];
    cell.headerLabel.font = [UIFont systemFontOfSize:14];

    cell.subLabel.font = [UIFont systemFontOfSize:12];
    cell.subLabel.textColor = [UIColor darkGrayColor];
    cell.subLabel.numberOfLines = 2;
    switch (indexPath.section) {
        case 0:
        {
            UIFont *font = [UIFont systemFontOfSize:14.0];
            NSDictionary *firstAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,[UIColor darkGrayColor],NSForegroundColorAttributeName,nil];
            UIFont *secondFont = [UIFont systemFontOfSize:10.0];
            NSDictionary *secondAttributes = [NSDictionary dictionaryWithObjectsAndKeys:secondFont,NSFontAttributeName,[UIColor lightGrayColor],NSForegroundColorAttributeName,nil];
            NSString* completeString = [NSString stringWithFormat:@"%@  |  %@",[_libraryPdfArray objectAtIndex:indexPath.row],[_libraryPdfDateArray objectAtIndex:indexPath.row]];
            NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]     initWithString:completeString];
            [attributedString setAttributes:firstAttributes range:[completeString rangeOfString:[_libraryPdfArray objectAtIndex:indexPath.row]]];
            [attributedString setAttributes:secondAttributes range:[completeString rangeOfString:[_libraryPdfDateArray objectAtIndex:indexPath.row]]];            
            cell.headerLabel.attributedText = attributedString;

            cell.subLabel.text = [_libraryPdfSubtitleArray objectAtIndex:indexPath.row];

        }
            break;

        case 1:
        {
            UIFont *font = [UIFont systemFontOfSize:14.0];
            NSDictionary *firstAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,[UIColor darkGrayColor],NSForegroundColorAttributeName,nil];
            NSString* completeString = [NSString stringWithFormat:@"%@  |  %@",[_ebriefingPdfArray objectAtIndex:indexPath.row],[_ebriefingSecondLabelTextArray objectAtIndex:indexPath.row]];
            NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]     initWithString:completeString];
            [attributedString setAttributes:firstAttributes range:[completeString rangeOfString:[_ebriefingPdfArray objectAtIndex:indexPath.row]]];
            [attributedString setAttributes:firstAttributes range:[completeString rangeOfString:[_ebriefingSubtitleArray objectAtIndex:indexPath.row]]];
            cell.headerLabel.attributedText = attributedString;
            cell.subLabel.text = [_ebriefingSubtitleArray objectAtIndex:indexPath.row];
        }
            break;

        default:
            break;
    }

    return cell;
}
Fügen Sie bitte einen Kommentar, warum Sie wählten ihn nach unten.
Meine Vermutung ist, dass Sie nicht negativ Stimmen, wenn Sie uns zeigen, was Sie bisher getan haben.
siehe meine Antwort unter diesem link stackoverflow.com/questions/14068962/... 🙂

InformationsquelleAutor Ankit Srivastava | 2013-06-28

Schreibe einen Kommentar