码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 开发中的一些小功能

时间:2015-01-16 18:33:39      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

1.本地通知,应用按HOME退出到后台,10秒后本地发起通知。(类似于push通知)

UILocalNotification *notification=[[UILocalNotification alloc] init]; 

if (notification!=nil) { 

NSLog(@">> support local notification"); 

NSDate *now=[NSDate new]; 

notification.fireDate=[now addTimeInterval:10]; 

notification.timeZone=[NSTimeZone defaultTimeZone]; 

notification.alertBody=@"该去吃晚饭了!"; 

[[UIApplication sharedApplication].scheduleLocalNotification:notification];

}

2.判断邮箱输入是否正确。

- (BOOL) validateEmail: (NSString *) candidate {

NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"; 

NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 

return [emailTest evaluateWithObject:candidate];

}

3.如何保存当前视图到相册。

#import <QuartzCore/QuartzCore.h>

UIGraphicsBeginImageContext(currentView.bounds.size);     //currentView 当前的view

[currentView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

 

iOS 开发中的一些小功能

标签:

原文地址:http://www.cnblogs.com/nfsq/p/4228988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!