2013-03-09 31 views
0

我想使用包含UITextfield,UITextview和UIImage的不同單元格製作UITable。我想生成一個類似報告的pdf,其中包含所有包含圖像和文本的單元格。合併屏幕截圖和pdf文件的生成

我有代碼爲UITableviewcell製作一個屏幕截圖。但我不知道如何製作多個屏幕截圖,然後將它們合併在一起形成一個pdf文件。

下面是我製作UITableviewcell截圖的代碼。由於

NSUInteger index[] = {0, 0}; // section, row 
    NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndexes:index length:2]; 

    // Get the cell 
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

    // Render a graphics context to turn your cell into a UIImage 
    CGSize imageSize = cell.bounds.size; 
    UIGraphicsBeginImageContext(imageSize); 
    CGContextRef imageContext = UIGraphicsGetCurrentContext(); 

    [cell.layer renderInContext:imageContext]; 



    // Retrieve the screenshot image 

    UIImage *imagefinal = UIGraphicsGetImageFromCurrentImageContext(); 



     UIGraphicsEndImageContext(); 

    UIImageWriteToSavedPhotosAlbum(imagefinal, nil, nil, nil); 
+1

XCode合併?????編輯。 – 2013-03-09 15:42:40

+0

@AnoopVaidya你是我的英雄。 – 2013-03-09 15:51:02

+0

@ H2CO3:從你們那裏瞭解到,今天我在面試的同時罵了4位候選人說同樣的話:) – 2013-03-09 16:05:34

回答

1

我不知道如何利用多屏幕截圖,但我甲肝做了一些編碼合併需要進行一些修改這個代碼合併多截圖兩個圖像。這是代碼。

 CGSize endImageSize = CGSizeMake(0, 0); 

     endImageSize = CGSizeMake(CELL_IMAGE_WIDTH,DesiredHeight); 


     UIGraphicsBeginImageContext(endImageSize); 

     // draw images into this context 
     [anOriginalImage1 drawInRect:CGRectMake(0, 0, 
               endImageSize.width, IMAGE1_HEIGHT)]; 
     [anOriginalImage2 drawInRect:CGRectMake(0, IMAGE1_HEIGHT, 
              endImageSize.width, IMAGE2_HEIGHT)]; 

     //convert context into a UIImage 
     UIImage *endImage = UIGraphicsGetImageFromCurrentImageContext(); 

     //cleanup 
     UIGraphicsEndImageContext();