电子邮件自定义相册图片

时间:2013-07-04 10:56:18

标签: iphone uiimagepickercontroller mfmailcomposeviewcontroller

我创建了用于拍摄照片的自定义相册。我在我的应用程序中调用了这张专辑。单击按钮后,将调用相册。但我无法将此图像分享给邮件。我使用MFMailComposeViewController进行发送。

代码:

photopick= [UIButton buttonWithType:UIButtonTypeCustom];
    [photopick setImage:[UIImage imageNamed:@"photo.png"] forState:UIControlStateNormal];
    // [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];

    [photopick setFrame:CGRectMake(10, 10, 80, 50)];

    [photopick addTarget:self action:@selector(showAlbum:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:photopick];

-(void)showAlbum:(id)sender{

    imagePicker=[[UIImagePickerController alloc]init];

    imagePicker.delegate = self;

    imagePicker.allowsEditing =NO;

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

   // imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;


    [self presentModalViewController:imagePicker animated:YES];

}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image

    [self.navigationController.navigationBar setHidden:NO];




    //  newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

    newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

    [newImage setFrame:CGRectMake(0, 0, 320, 568)];

    //  [newImage setUserInteractionEnabled:YES];



    [self.view addSubview:newImage];

    // [newImage release];


    [picker dismissModalViewControllerAnimated:YES];

}

选择图像后,我有其他按钮将newImage(相册图像)发送到邮件:

-(void)send:(id)sender{

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

        picker.mailComposeDelegate = self;
        [picker setSubject:@"My image"];

        UIImage *roboPic = [UIImage imageNamed:@"RobotWithPencil.jpg"];

        NSData *imageData = UIImageJPEGRepresentation(roboPic, 1);
        [picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"RobotWithPencil.jpg"];




        NSString *emailBody = @"This is a cool image of a robot I found.  Check it out!";
        [picker setMessageBody:emailBody isHTML:YES];

        [self presentModalViewController:picker animated:YES];

}

但是如何将专辑图像设置为MFMailComposeViewController内部。使用的一些文档使用[UIImage imageNamed:@"img.png"];这里我没有imageName。我有来自专辑的图片

1 个答案:

答案 0 :(得分:0)

尝试使用以下链接

MFMail

您可以使用for循环在Messagebody中设置多个图像。

使用此功能设置邮件正文

     - (NSString *)messageBody
     {
         // if we couldn't fetch the app information, use a simple fallback template
         if (self.applicationSellerName==nil) {
             // Fill out the email body text
             NSMutableString *emailBody = [NSMutableString stringWithFormat:@"<div> \n"
                                  "<p style=\"font:17px Helvetica,Arial,sans-serif\">%@</p> \n"
                                  "<h1 style=\"font:bold 16px Helvetica,Arial,sans-serif\"><a target=\"_blank\" href=\"%@\">%@</a></h1> \n"
                                  "<br> \n"
                                  "<table align=\"center\"> \n"
                                  "<tbody> \n"
                                  "<tr> \n"
                                  "<td valign=\"top\" align=\"center\"> \n"
                                  "<span style=\"font-family:Helvetica,Arial;font-size:11px;color:#696969;font-weight:bold\"> \n"
                                  "</td> \n"
                                  "</tr> \n"
                                  "<tr> \n"
                                  "<td align=\"left\"> \n"
                                  "<span style=\"font-family:Helvetica,Arial;font-size:11px;color:#696969\"> \n"
                                  "Please note that you have not been added to any email lists. \n"
                                  "</span> \n"
                                  "</td> \n"
                                  "</tr> \n"
                                  "</tbody> \n"
                                  "</table> \n"
                                  "</div>",
                                  self.message,
                                  [self.appStoreURL absoluteString],
                                  self.applicationName
                                  ];

             return emailBody;

         }