2017-03-04 1 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

그래서 알아 냈습니다. 누군가가 여기에 관심이있는 경우에는 내가 어떻게했는지입니다.

지금처럼 텍스트 뷰에 제대로 설정의 조합 그것은되었다, 나는 다음과 같이 표시를 "제목"내있는 tableView에서

다음과 같이 첫 번째 줄을 저장

-(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; 

} 

설정 : (나는 내가 바꾸었던 재료 대신에 전체 셀 호출을 제공 할 것이다).

- (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]; 
} 

희망이 있으면 누군가에게 도움이 될 것입니다.

관련 문제