iOS/oc 保存tableview长图

- (UIImage*)screenShotForIndexPaths{


    CGSize size=CGSizeMake(SCREEN_WIDTH, 90 * self.dataArray.count+_headView.frame.size.height);

    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);


    CGContextRef ctx = UIGraphicsGetCurrentContext();

    [_headView.layer renderInContext:ctx];


    //绘制表头

    CGContextTranslateCTM(ctx, 0,_headView.frame.size.height);

    //---一個一個把cell render到CGContext上

    for(inti=0;i<self.dataArray.count;i++)

    {

        HXSelfTestDataModel*model=self.dataArray[i];

        HxSelfTestViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NSStringFromClass(HxSelfTestViewCell.class)];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        [cellsetFrame:CGRectMake(0,90* i+_headView.frame.size.height,SCREEN_WIDTH,90)];

        [cell.contentView setBackgroundColor:[HXColorTool getDefCellColor]];

        [cellsetViewWithModel:model];


        [cell.contentView.layer renderInContext:ctx];

        //绘制cell

        CGContextTranslateCTM(ctx, 0, 90);

    }


    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();


    UIGraphicsEndImageContext();


    returnimage;

}

你可能感兴趣的:(iOS/oc 保存tableview长图)