UIButtonã®ç»åãPNGãã¡ã¤ã«ã«ä¿åããæ¹æ³
以ä¸ã®æ§ãªè¨è¿°ã§ UIButton ã®å¤è¦³ã®ç»åãã¼ã¿ãã¢ããªã® Documents 以ä¸ã« test.png ã¨ããå称㧠ä¿åããã¾ããä»ã®GUIã«ã¤ãã¦ãåæ§ã®æ¹æ³ã§ãã¡ã¤ã«ã«ä¿åã§ãã¾ãã
(ãµã³ãã«ã®å
¨ä½ã¯こちらããDLãã¦ä¸ãã)
- (IBAction)run:(id)sender { UIGraphicsBeginImageContext(self.button.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [self.button.layer renderInContext:context]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *data = UIImagePNGRepresentation(image); NSString *filePath = [NSString stringWithFormat:@"%@/test.png" , [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]]; NSLog(@"%@", filePath); if ([data writeToFile:filePath atomically:YES]) { NSLog(@"OK"); } else { NSLog(@"Error"); } [data release]; }