项目中需要添加MessageUi.framework。
头文件加入MFMailComposeViewControllerDelegate。
#import <MessageUI/MessageUI.h>  


一、创建视图控制器:

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;


二、设置邮件主题:

[mc setSubject:@"Hello, World!"];


三、设置收件人,收件人有三种:

1、设置主收件人

[mc setToRecipients:[NSArray arrayWithObjects:@"zhuqi0@126.com",
        "@dave@iphonedevbook.com", nil];


2、设置cc

[mc setCcRecipients:[NSArray arrayWithObject:@"zhuqil@163.com"]];


3、设置bcc

[mc setBccRecipients:[NSArray arrayWithObject:@"secret@gmail.com"]];


四、设置邮件主体,有两种格式。

一种是纯文本

  [mc setMessageBody:@"Watson!!!\n\nCome here, I need you!" isHTML:NO];


一个是html格式

[mc setMessageBody:@"<HTML><B>Hello, Joe!</B><BR/>What do you know?</HTML>"
        isHTML:YES];


五、添加附件

添加附件需要三个参数,一个是NSData类型的附件,一个是mime type,一个附件的名称。

  NSString *path = [[NSBundle mainBundle] pathForResource:@"blood_orange"      
      ofType:@"png"];
  NSData *data = [NSData dataWithContentsOfFile:path];
  [mc addAttachmentData:data mimeType:@"image/png" fileName:@"blood_orange"];  


六、视图呈现

    [self presentModalViewController:mc animated:YES];
    [mc release];


七、视图控制器的委托方法

邮件视图控制器的委托方法包含在MFMailComposeViewControllerDelegate中,无论用户是否发送或取消发送,不论系统是否能够发送邮件,

方法 mailComposeController:didFinishWithResult:error: gets called都会被调用。


- (void)mailComposeController:(MFMailComposeViewController*)controller  
        didFinishWithResult:(MFMailComposeResult)result  
        error:(NSError*)error {  
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail send canceled...");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved...");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent...");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail send errored: %@...", [error localizedDescription]);
            break;
        default:
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}


  
作者:朱祁林
出处:http://zhuqil.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
You can do exactly that via the various sizeWithFont: methods in NSString UIKit Additions. In your case the simplest variant should suffice (since you don't have multi-line labels):

NSString *someString = @"Hello World";
UIFont *yourFont = // [UIFont ...]
CGSize stringBoundingBox = [someString sizeWithFont:yourFont];


What you want is in UIStringDrawing.h

CGFloat  actualFontSize = 12.0;
CGSize sizeNeeded = [plainText sizeWithFont:[UIFont systemFontOfSize:12.0] minFontSize:12.0
      actualFontSize:&actualFontSize forWidth:widthOfMyLabel lineBreakMode:UILineBreakModeTailTruncation];


摘自 http://stackoverflow.com/q...
碰到这样的错误:JSONValue failed. Error is: Unescaped control character [0x09]

有如下解决方案:
-(NSString *)removeUnescapedCharacter:(NSString *)inputStr
{

NSCharacterSet *controlChars = [NSCharacterSet controlCharacterSet];

NSRange range = [inputStr rangeOfCharacterFromSet:controlChars];

  if (range.location != NSNotFound)
  {

      NSMutableString *mutable = [NSMutableString stringWithString:inputStr];

      while (range.location != NSNotFound)
      {

          [mutable deleteCharactersInRange:range];

          range = [mutable rangeOfCharacterFromSet:controlChars];

      }

      return mutable;

   }

  return inputStr;
}


Call this method with passing your output string like this
NSString *output = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"yourUrlString"] encoding:NSUTF8StringEncoding error:nil];

output = [self removeUnescapedCharacter:output];


http://stackoverflow.com/q...
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1.gif" ofType:nil];
SCGIFImageView *gifImageView = [[[SCGIFImageView alloc] initWithGIFFile:filePath] autorelease];
gifImageView.frame = CGRectMake(0, 0, gifImageView.image.size.width, gifImageView.image.size.height);
gifImageView.center = self.view.center;
[self.view addSubview:gifImageView];


gifImageView.image.size就是gif的宽高了
MBProgressHUD *mb = [MBProgressHUD showHUDAddedTo:self.scroller animated:YES];
[mb setLabelText:NSLocalizedString(@"加载大图..",nil)];

dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
    
    NSURL *url2 = [NSURL URLWithString:url];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url2];

    //指定来源
    [request setValue:@"http://www.aslibra.com/" forHTTPHeaderField:@"Referer"];
    //[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22" forHTTPHeaderField:@"User-Agent"];
    
    NSError *error = nil;
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImage *img = [UIImage imageWithData:data];
        [MBProgressHUD hideHUDForView:self.scroller animated:YES];
    });
});
分页: 10/26 第一页 上页 5 6 7 8 9 10 11 12 13 14 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐