だから私はこれまでに2つのテキストフィールドを作成しました。テキストフィールドはメールコンポーザに接続されており、ユーザーがそれらに書いたものは何でもメールコンポーザに表示されますが、UIImageViewに対して同じことを行う方法がわかりません.ユーザーが写真を選択するか、写真を撮って、それがメール作成ツールにも自動的に追加されるようにします。
@interface xyzViewController ()
@end
@implementation xyzViewController
- (IBAction)savedata:(id)sender; {
NSString *savestring = _mytextview.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:@"savedstring"];
[defaults synchronize];
NSString *savestring1 = _mytextview1.text;
NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults];
[defaults1 setObject:savestring1 forKey:@"savedstring1"];
[defaults synchronize];
}
- (IBAction)loaddata:(id)sender; {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:@"savedstring"];
[_mytextview setText:loadstring];
[label setText:loadstring];
NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults];
NSString *loadstring1 = [defaults objectForKey:@"savedstring1"];
[_mytextview1 setText:loadstring1];
}
- (IBAction)dismiss:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)dismiss1:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sendButton:(id)sender {
MFMailComposeViewController *mailContoller = [[MFMailComposeViewController alloc]init];
[mailContoller setMailComposeDelegate:self];
NSString *email = @"avip606@gmail.com";
NSString *email1 = @"avi_sp@hotmail.co.uk";
NSArray *emailArray = [[NSArray alloc]initWithObjects:email, email1, nil];
NSString *message = [@[_mytextview.text, _mytextview1.text] componentsJoinedByString: @"\n"];
[mailContoller setMessageBody:message isHTML:NO];
NSData *data = UIImagePNGRepresentation(_image);
[mailContoller addAttachmentData:data
mimeType:@"image/png"
fileName:@"image.png"];
[mailContoller setToRecipients:emailArray];
[mailContoller setSubject:@"IT WORKS!"];
[self presentViewController:mailContoller animated:YES completion:nil];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self mytextview] resignFirstResponder];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end