iOS/oc 保存tableview长图

2022-09-05  本文已影响0人  阿两sama

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

}

上一篇 下一篇

猜你喜欢

热点阅读