1

我创建了一个UITableViewCell与 iOS6 完美配合的自定义,现在在 iOS7 中我只能获得标准的白色背景,而没有任何我自定义的单元 UI 对象。

我注意到苹果引入了一个新的观点,UITableView但我应该如何处理呢?

我试过了:

    - cell.contentView.backgroundColor = [UIColor clearColor]; 
      within UITableViewController cellForRowAtIndexPath but without effect :(

UITableViewController:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PdfFile *file = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    int maxCells = [[pdfDS.ditcDocuments objectAtIndex:indexPath.section] count];
    MedialoungeDocumentTableViewCell *cell = [[MedialoungeDocumentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DocumentTableCell"];

    [cell setDocumentTitle: file.fileTitle];
    [cell setFirstElement:(indexPath.row == 0) ? YES:NO];
    [cell setLastElement:(indexPath.row == (maxCells -1)) ? YES:NO ];
    NSString *subTitle = [file.fileSubtitle isEqualToString:@""]?@"":file.fileSubtitle;

    if([file.documentKind isEqualToString: PDFKIND_SUCCESS]){
        [cell setDocumentKind:PDFDOCTYPE_SUC];
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@",subTitle]];
    }else if([file.documentKind isEqualToString:PDFKIND_SOLUTION]){
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@", subTitle]];
        [cell setDocumentKind:PDFDOCTYPE_SOL];
    }else if([file.documentKind isEqualToString:PDFKIND_RESEARCH]){
        [cell setDocumentSubtitle:[NSString stringWithFormat:@"%@", subTitle]];
        [cell setDocumentKind:PDFDOCTYPE_WP];
    }

    cell.contentView.backgroundColor = [UIColor clearColor];
    return cell;

}

我的习惯UITableViewCell

- (void)drawContentView:(CGRect)rect highlighted:(BOOL)highlighted {
    //// Color Declarations
    UIColor* grey = [UIColor colorWithRed: 0.178 green: 0.178 blue: 0.178 alpha: 1];
    UIColor* color4 = [UIColor colorWithRed: 0.611 green: 0.611 blue: 0.611 alpha: 1];
    UIColor* color6 = [UIColor colorWithRed: 0.529 green: 0.529 blue: 0.529 alpha: 1];
    UIColor* active = CUSTOM_COLOR(62, 62, 62, 1);
    //// Abstracted Attributes
    NSString* dcoumentTitleContent = self.documentTitle;
    NSString* subtitleContent = self.documentSubtitle;

    //// background Drawing
    UIBezierPath* backgroundPath = [UIBezierPath bezierPath];
    [backgroundPath moveToPoint: CGPointMake(8, 60)];
    [backgroundPath addLineToPoint: CGPointMake(8, 0)];
    [backgroundPath addLineToPoint: CGPointMake(30, 0)];
    [backgroundPath addLineToPoint: CGPointMake(930.00, 0)];
    if(lastElement){
        [backgroundPath addLineToPoint: CGPointMake(930.00, 50.00)];
    }else{
        [backgroundPath addLineToPoint: CGPointMake(930.00, 60.00)];
    }
    [backgroundPath addLineToPoint: CGPointMake(920, 60)];
    [backgroundPath addLineToPoint: CGPointMake(8, 60)];
    [backgroundPath closePath];
    if(highlighted){
        [active setFill];
    }else{
        [grey setFill];
    }
    [backgroundPath fill];

    //// colorStripe Drawing
    UIBezierPath* colorStripePath = [UIBezierPath bezierPath];
    [colorStripePath moveToPoint: CGPointMake(0, 60)];
    [colorStripePath addLineToPoint: CGPointMake(0, 0)];
    [colorStripePath addCurveToPoint: CGPointMake(10, 0) controlPoint1: CGPointMake(0,0) controlPoint2: CGPointMake(10, 0)];
    [colorStripePath addCurveToPoint: CGPointMake(10, 60) controlPoint1: CGPointMake(10, 0) controlPoint2: CGPointMake(10, 60)];
    [colorStripePath addLineToPoint: CGPointMake(0, 60)];
    [colorStripePath closePath];
    if(documentKind == PDFDOCTYPE_SOL){
        [CUSTOM_COLOR(SOL_COLOR_R, SOL_COLOR_G, SOL_COLOR_B, SOL_COLOR_A) setFill];
    }else if (documentKind == PDFDOCTYPE_SUC){
        [CUSTOM_COLOR(SUC_COLOR_R, SUC_COLOR_G, SUC_COLOR_B, SUC_COLOR_A) setFill];
    }else if(documentKind == PDFDOCTYPE_WP){
        [CUSTOM_COLOR(WP_COLOR_R, WP_COLOR_G, WP_COLOR_B, WP_COLOR_A) setFill];
   }

    [colorStripePath fill];

    //// dcoumentTitle Drawing
    CGRect documentTitleRect = CGRectMake(78, 7, 800, 40);
    [color4 setFill];

    if (SYSTEM_VERSION_LESS_THAN(@"7")){
        [dcoumentTitleContent drawInRect: documentTitleRect withFont: [UIFont fontWithName: @"Helvetica-Bold" size: 21.5] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
    }else{
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
        [style setAlignment:NSTextAlignmentLeft];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        CGFloat fontSize = 21.5;
        UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

        NSDictionary *dict=@{
                             NSFontAttributeName : font,
                             NSParagraphStyleAttributeName: style
                             };

        [dcoumentTitleContent drawInRect:documentTitleRect withAttributes:dict];
    }


    //// subtitle Drawing
    CGRect subtitleRect = CGRectMake(79, 32, 800, 22);
    [color6 setFill];
    if (SYSTEM_VERSION_LESS_THAN(@"7")){
        [subtitleContent drawInRect: subtitleRect withFont: [UIFont fontWithName: @"Helvetica-Bold" size: 13] lineBreakMode: NSLineBreakByWordWrapping alignment: NSTextAlignmentLeft];
    }else{
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
        [style setAlignment:NSTextAlignmentLeft];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        CGFloat fontSize = 13.0;
        UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

        NSDictionary *subDict=@{
                             NSFontAttributeName : font,
                             NSParagraphStyleAttributeName: style
                             };
        [subtitleContent drawInRect:subtitleRect withAttributes:subDict];

    }
    UIImage *img= [UIImage imageNamed:@"doc_icon.png"];
    [img drawInRect:CGRectMake(35, 10, 28, 40)];
}

有人知道我能做什么吗?

屏幕: 1. 看起来 没有单元格 ui 对象

  1. 所以它应该看起来像 在此处输入图像描述
4

0 回答 0