2017-03-04 4 views
0

私の検索で、私は私の答えを見つけることができませんでした。ノートアプリケーションのような表ビューセル

基本的に私はビューコントローラのような基本的なメモを持っています。私は最初の行が音符のタイトルであり、残りの部分が字幕内にある音符のようなエフェクトが欲しいです。

NSString *note = nil; 
if (tableView == self.tableView) { 
    note = [noteArray objectAtIndex:indexPath.row]; 
} 
NSString *date = [dateArray objectAtIndex:indexPath.row]; 
NSInteger charnum = [note length]; 
if (charnum >= 22) { 
    cell.textLabel.text = [[note substringToIndex:18] stringByAppendingString:@"..."]; 
} 
else{ 
    cell.textLabel.text = note; 
} 

[cell.detailTextLabel setText:[NSString stringWithFormat:@"%@ - %@", date, [note substringFromIndex:18]]]; 
[cell.detailTextLabel setNumberOfLines:1]; 

今のところは18文字まで読み取り、...と字幕が休息のためにそれをピックアップ:私はそれがセットアップされている方法

タイトル/ヘッダーを設定してから本文を設定するにはどうすればよいですか?

答えて

0

私はそれを理解しました。誰かがここで興味を持っている場合は、私がそれをやった方法です。

それはとても似のTextViewにそれを適切に設定する組み合わせた:

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { 

    NSMutableString *newString = [NSMutableString stringWithString:self.textView.text]; 
    [newString replaceCharactersInRange:range withString:text]; 
    NSString *trimmed = [newString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 
    NSRange newLineRange = [trimmed rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]]; 
    if(newLineRange.length > 0) 
    { 
     self.textView.text = [trimmed substringToIndex:newLineRange.location]; 
    } 
    else { 
     self.textView.text = trimmed; 
    } 

    return YES; 

} 

「タイトル」私のtableViewで

次のように最初の行を保存し、私は以下のように表示を設定します:(私が変更したものの代わりに私の全セル電話を提供するつもりです)。

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

    [cell setSelectionStyle:UITableViewCellSelectionStyleDefault]; 
    [cell.textLabel setNumberOfLines:1]; 
    [cell.textLabel setLineBreakMode : NSLineBreakByTruncatingTail]; 
    [cell setClipsToBounds:YES]; 

    // Configure the cell label. 
    [cell.textLabel setTextColor: [UIColor whiteColor]]; 
    [cell.textLabel setFont:[UIFont boldSystemFontOfSize:18]]; 

    //Cell Base color 
    [cell.contentView.superview setBackgroundColor:[UIColor colorWithRed:0.271 green:0.271 blue:0.271 alpha:1]]; 

    //Cell selection color 
    UIView *cellColor = [[UIView alloc] init]; 
    [cellColor setBackgroundColor:[UIColor colorWithRed:0.176 green:0.176 blue:0.176 alpha:0.95]]; 
    [cell setSelectedBackgroundView:cellColor]; 

    //Cell border 
    [cell.layer setBorderColor:[UIColor colorWithRed:30/255.0 green:30/255.0 blue:30/255.0 alpha:1.0].CGColor]; 
    [cell.layer setBorderWidth:1.5f]; 

    //Setting the first line of cell. 
    NSString *note = nil; 
    if (tableView == self.tableView) { 
     note = [noteArray objectAtIndex:indexPath.row]; 
    } 
    cell.textLabel.text = note; 

    //Subtitle line. 
    NSRange startRange = NSMakeRange(1, 0); 
    NSRange titleRange = [note lineRangeForRange:startRange]; 
    NSString *titleString = [note substringFromIndex:titleRange.length]; 
    titleString = [titleString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 
    //titleString = [titleString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""]; 

    //Setting the date. 
    NSString *date = [dateArray objectAtIndex:indexPath.row]; 

    [cell.detailTextLabel setNumberOfLines:1]; 

    //New method of having two seperate colors for the detail string. 
    NSAttributedString *scoreAttributedString = [[NSAttributedString alloc] initWithString:date attributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:0.20 green:0.67 blue:0.86 alpha:1.0]}]; 
    NSAttributedString *domainAttributedString = [[NSAttributedString alloc] initWithString:titleString attributes:@{NSForegroundColorAttributeName: [UIColor lightTextColor]}]; 

    NSMutableAttributedString *detailMutableAttributedString = [[NSMutableAttributedString alloc] init]; 
    [detailMutableAttributedString appendAttributedString:scoreAttributedString]; 
    [detailMutableAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]]; 
    [detailMutableAttributedString appendAttributedString:domainAttributedString]; 

    [[cell detailTextLabel] setAttributedText:detailMutableAttributedString]; 
} 

これは誰かに役立つことを望みます。

関連する問題