20100-10-31 ChineseName 中技术要点备忘

截屏操作

// 对指定 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];
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值