截屏操作
// 对指定 UIView 截屏并保存到IPHONE相册中
-(void) saveViewToPhoto:(UIView*) view
{
if(view == nil)
{
view = self.view;
}
CGSize size = view.bounds.size;
size.height = size.height - 37; // 减去 操作“按钮”
UIGraphicsBeginImageContext(size); //
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
// 使用MFMailComposeViewController
// MFMailComposeViewController 是IPHONE 内置发邮件组件,使用它可以在自己的应用弹出发邮件界面且不需要退出当前应用。 MFMailComposeViewController 可以在程序中指定接收人组、抄送组、邮件主体及附件也可以在弹出的界面中手工指定
使用条件:
1. 首先需要设备支持 在IPHONE 或IPOD TOUCH 中设置好一个可用邮件。
2. 开发SDK 要3.0以后
其它的就是代码了 如下:
// 首判断你的设备或系统是否能够使用MFMailComposeViewController 发送邮件
BOOL isCanSend = [MFMailComposeViewController canSendMail];
if (isCanSend == NO)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Send Error", @"")
message:NSLocalizedString(@"Can'nt Send EMail.", nil)
delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", "ok") otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
// 创建 MFMC 实例
MFMailComposeViewController* eMailPicker = [[MFMailComposeViewController alloc] init];
// 指定处理委托 为当前类
eMailPicker.mailComposeDelegate = self;
// 设置标题
[eMailPicker setSubject:[NSString stringWithFormat:@"%@ %@",enName.text, NSLocalizedString(@"Chinese Name Information", nil)]];
// 获取主体 内容可以自定义
NSString* emailBoy = [self getEMailBody];
// 设置邮件主体 非HTML格式
[eMailPicker setMessageBody:emailBoy isHTML:NO];
// 生成一个附件二进制数据
NSData* a1 = UIImagePNGRepresentation(totemImageView.image);
// 添加一个附件 PNG图像
[eMailPicker addAttachmentData:a1 mimeType:@"image/png" fileName:totemName.text];
// 添加另一个附件
NSData* a2 = UIImagePNGRepresentation(propertyImageView.image);
[eMailPicker addAttachmentData:a2 mimeType:@"image/png" fileName:propertyName.text];
弹出发邮件界面
[self presentModalViewController:eMailPicker animated:YES];
[eMailPicker release];
还需要一个返回处理状态的 委托
// 根据发送邮件 邮件服务器处理返回状态 在界面上做相应的提示信息 并消掉邮件发送界面。
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString* sendInfo;
if (result == MFMailComposeResultCancelled)
{
sendInfo = [NSString stringWithString:NSLocalizedString(@"Send EMail Cancelled!", nil)];
}
else if(result == MFMailComposeResultSaved)
{
sendInfo = [NSString stringWithString:NSLocalizedString(@"Send EMail Saved!", nil)];
}
else if(result == MFMailComposeResultFailed)
{
sendInfo = [NSString stringWithString:NSLocalizedString(@"Send EMail Failed!", nil)];
}
else
{
sendInfo = [NSString stringWithString:NSLocalizedString(@"Send EMail Sent!", nil)];
}
[self dismissModalViewControllerAnimated:YES];
// NSLocalizedString(@"Send Succeeded!", nil)
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Send EMail", nil)
message:sendInfo delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",nil) otherButtonTitles:nil];
[alert show];
[alert release];
}