2014-01-23 45 views
-2

我想用Uilabeltextfield保存圖像。 我可以保存它們,但所有的文本框都是黑色的。 我嘗試從屬性檢查器更改,但沒有任何更改。 任何人都可以幫助我將Uilabel文本字段保存爲白色。 也我需要粗體字體。用文本顏色保存Uilabel

謝謝。

UIGraphicsBeginImageContextWithOptions(self.mainImage.bounds.size, YES, 0.0); 
    [self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    [self.goalkeeperImage.image drawInRect:CGRectMake(self.goalkeeperImage.frame.origin.x, self.goalkeeperImage.frame.origin.y, self.goalkeeperImage.frame.size.width, self.goalkeeperImage.frame.size.height)]; 
    [self.goalkeeperText.text drawInRect:CGRectMake(self.goalkeeperText.frame.origin.x, self.goalkeeperText.frame.origin.y, self.goalkeeperText.frame.size.width,self.goalkeeperText.frame.size.height) withAttributes:nil ]; 
    [self.datelabeltext.text drawInRect:CGRectMake(self.datelabeltext.frame.origin.x, self.datelabeltext.frame.origin.y, self.datelabeltext.frame.size.width,self.datelabeltext.frame.size.height) withAttributes: nil ]; 

    UIImage *SaveImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    UIImageWriteToSavedPhotosAlbum(SaveImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil); 
+0

使用'JavasText'而不是'text'。然後,您可以使用任何您需要的字體屬性和顏色來設置屬性文本。 – rmaddy

+0

我改變了; [self.datelabeltext.attributedText drawWithRect:CGRectMake(self.datelabeltext.frame.origin.x,self.datelabeltext.frame.origin.y,self.datelabeltext.frame.size.width,self.datelabeltext.frame.size.height)選項:@selector(fontAttributes)context:nil];它的工作原理,但Xcode給我一個警告「'不兼容指針整數轉換髮送'SEL'類型參數'NSStringDrawingOptions'(又名'枚舉NSStringDrawingOptions') – user3106377

回答

0

如果所有的圖像和你試圖渲染標籤都包含在一個單一的視圖中(並且沒有其他對象存在),你可以使用此代碼來捕獲含觀點:

// Draw the high resolution image to the context 
UIGraphicsBeginImageContextWithOptions(drawView.bounds.size, NO, 0.0); 
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *ViewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

// Save the high resolution image as a png 
NSData *pngData = UIImagePNGRepresentation(ViewImage); 
[pngData writeToFile:@"__Path__/[email protected]" atomically:NO]; 

// Draw the low resolution image to the context 
UIGraphicsBeginImageContext(drawView.bounds.size); 
[[drawView layer] renderInContext:UIGraphicsGetCurrentContext()]; 
ViewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

// Save the low resolution image as a png 
pngData = UIImagePNGRepresentation(ViewImage); 
[pngData writeToFile:@"__Path__/image.png" atomically:NO]; 

您可能不需要代碼將圖像另存爲PNG,您可以使用ViewImage作爲您傳遞給另一個函數的UIImage。這只是我用來將視圖保存爲png的代碼。