cocoa论坛会员源码分享
来源:互联网 发布:python高斯分布散点图 编辑:程序博客网 时间:2024/04/30 21:45
开机动画(会员qqy620)
上传一个开机动画Demo
附件:
/cms/uploads/soft/131107/4196-13110G05F0.zip原帖:http://www.cocoachina.com/bbs/read.php?tid=137552
NSDateFormatter整理(会员qqy620)
NSDate对象包含两个部分,日期(Date)和时间(Time)。格式化的时间字符串主要也是针对日期和时间的
1、基础用法
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateStyle = kCFDateFormatterShortStyle;
fmt.timeStyle = kCFDateFormatterShortStyle;
fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString* dateString = [fmt stringFromDate:now];
NSLog(@"%@", dateString);
[fmt release];
打印输出:10/29/12, 2:27 PM
这使用的系统提供的格式化字符串,通过 fmt.dateStyle 和 fmt.timeStyle 进行的设置。实例中使用的参数是 kCFDateFormatterShortStyle,此外还有:
typedef CF_ENUM(CFIndex, CFDateFormatterStyle) { // date and time format styles
kCFDateFormatterNoStyle = 0, // 无输出
kCFDateFormatterShortStyle = 1, // 10/29/12, 2:27 PM
kCFDateFormatterMediumStyle = 2, // Oct 29, 2012, 2:36:59 PM
kCFDateFormatterLongStyle = 3, // October 29, 2012, 2:38:46 PM GMT+08:00
kCFDateFormatterFullStyle = 4 // Monday, October 29, 2012, 2:39:56 PM China Standard Time
};
自己写的date转换成nsstring:
2. 自定义区域语言
如上实例中,我们使用的是区域语言是 en_US,指的是美国英语。如果我们换成简体中文,则代码是:
fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
则对应的输出为:
typedef CF_ENUM(CFIndex, CFDateFormatterStyle) { // date and time format styles
kCFDateFormatterNoStyle = 0, // 无输出
kCFDateFormatterShortStyle = 1, // 12-10-29 下午2:52
kCFDateFormatterMediumStyle = 2, // 2012-10-29 下午2:51:43
kCFDateFormatterLongStyle = 3, // 2012年10月29日 GMT+0800下午2时51分08秒
kCFDateFormatterFullStyle = 4 // 2012年10月29日星期一 中国标准时间下午2时46分49秒
};
世界通用的区域语言代码,详见 International Components for Unicode (ICU), http://userguide.icu-project.org/formatparse/datetime
3. 自定义日期时间格式
NSDateFormatter提供了自定义日期时间的方法,主要是通过设置属性 dateFormat,常见的设置如下:
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
fmt.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
NSString* dateString = [fmt stringFromDate:now];
NSLog(@"%@", dateString);
[fmt release];
打印输出:2012-10-29T16:08:40
除了上面列出的,还可以指定很多格式,详见http://userguide.icu-project.org/formatparse/datetime。
结合设置Locale,还可以打印出本地化的字符串信息。
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
fmt.dateFormat = @"yyyy-MM-dd a HH:mm:ss EEEE";
NSString* dateString = [fmt stringFromDate:now];
NSLog(@"\n%@", dateString);
[fmt release];
打印输出:2012-10-29 下午 16:25:27 星期一
4. 自定义月份星期等字符
NSDateFormatter中同样提供了相应的方式,去修改这些字符。一般情况下,使用相应区域语言下面的默认字符就OK了。但是你的确有这个需求,那么也是可以办到的。相应的方法非常多,如下:
Managing AM and PM Symbols
– AMSymbol
– setAMSymbol:
– PMSymbol
– setPMSymbol:
Managing Weekday Symbols
– weekdaySymbols
– setWeekdaySymbols:
– shortWeekdaySymbols
– setShortWeekdaySymbols:
– veryShortWeekdaySymbols
– setVeryShortWeekdaySymbols:
– standaloneWeekdaySymbols
– setStandaloneWeekdaySymbols:
– shortStandaloneWeekdaySymbols
– setShortStandaloneWeekdaySymbols:
– veryShortStandaloneWeekdaySymbols
– setVeryShortStandaloneWeekdaySymbols:
Managing Month Symbols
– monthSymbols
– setMonthSymbols:
– shortMonthSymbols
– setShortMonthSymbols:
– veryShortMonthSymbols
– setVeryShortMonthSymbols:
– standaloneMonthSymbols
– setStandaloneMonthSymbols:
– shortStandaloneMonthSymbols
– setShortStandaloneMonthSymbols:
– veryShortStandaloneMonthSymbols
– setVeryShortStandaloneMonthSymbols:
Managing Quarter Symbols
– quarterSymbols
– setQuarterSymbols:
– shortQuarterSymbols
– setShortQuarterSymbols:
– standaloneQuarterSymbols
– setStandaloneQuarterSymbols:
– shortStandaloneQuarterSymbols
– setShortStandaloneQuarterSymbols:
Managing Era Symbols
– eraSymbols
– setEraSymbols:
– longEraSymbols
– setLongEraSymbols:
date转换成nsstring方法:
- (NSString *)dateFromString:(NSString *)dateString
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateString];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSString *srting = [dateFormat stringFromDate:date];
[dateFormat release];
return srting;
}
带样式的时间转换
- (NSString *)dateFromStringWithDateStyle:(NSDateFormatterStyle)dateStyle
{
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateStyle = dateStyle;
fmt.timeStyle = dateStyle;
fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
NSString* dateString = [fmt stringFromDate:now];
[fmt release];
return dateString;
}
下面上传一个Dmeo
附件:
/cms/uploads/soft/131107/4196-13110G05I2.zip原帖:http://www.cocoachina.com/bbs/read.php?tid=134821
解决UITextView的placeholder属性(会员qqy620)
解决UITextView的placeholder属性,并解决了键盘遮挡问题
附件:
/cms/uploads/soft/131107/4196-13110G05J9.zip原帖:http://www.cocoachina.com/bbs/read.php?tid=134401
iPhone/iPad全屏截图Demo (会员qqy620)
全屏截图:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//保存到相册
CGRect rect = self.view.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
CGRect rect2 = CGRectMake(0, 0, 320 , 480);//创建矩形框
_imageView.image=[UIImage imageWithCGImage:CGImageCreateWithImageInRect([image CGImage], rect2)];//此处的_imageView是自定义的UIImageView,截的图在这里显示。
参考:http://www.cocoachina.com/bbs/read.php?tid=114736
截取本区域(self.view):
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
全屏截图:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片
苹果最新开放的接口函数(全屏截图),已经有人试过了,不会reject:
CGImageRef UIGetScreenImage();
CGImageRef img = UIGetScreenImage();
UIImage* scImage=[UIImage imageWithCGImage:img];
UIImageWriteToSavedPhotosAlbum(scImage, nil, nil, nil);
It still works,but only on-device (not in simulator) .
截图另存为指定名字:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *screenshotPNG = UIImagePNGRepresentation(screenshot);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError *error = nil;
[screenshotPNG writeToFile:[documentsDirectory stringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWrite error:&error];
部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app
没有ipad真机截图发布app的可以用此方法做个透明按钮点,哈哈.
截取本区域(self.view):
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
全屏截图:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片
苹果最新开放的接口函数(全屏截图),已经有人试过了,不会reject:
CGImageRef UIGetScreenImage();
CGImageRef img = UIGetScreenImage();
UIImage* scImage=[UIImage imageWithCGImage:img];
UIImageWriteToSavedPhotosAlbum(scImage, nil, nil, nil);
It still works,but only on-device (not in simulator) .
截图另存为指定名字:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *screenshotPNG = UIImagePNGRepresentation(screenshot);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError *error = nil;
[screenshotPNG writeToFile:[documentsDirectory stringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWrite error:&error];
部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app
附件:
/cms/uploads/soft/131107/4196-13110G10101.zip原帖:http://www.cocoachina.com/bbs/read.php?tid=124528
分享到微信Demo(会员qqy620)
参考官方文档;http://open.weixin.qq.com/document/gettingstart/ios/?lang=zh_CN; http://open.weixin.qq.com/document/sdk/ios/?lang=zh_CN;
注意下:如果使用XCode 4.3及以下版本,使用libWeChatSDK.a;如果使用XCode 4.5及以上版本,使用libWeChatSDK_armv7_v7s.a ,XCode 4.4版本,也是使用libWeChatSDK_armv7_v7s.a ,官方没有提到4.4版本。
官方的Demo看的很晕,自己以重新整理了一下。加了点功能:跳转到appstore上去下载 微信:NSString *weiXinLink = @"itms-apps://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:weiXinLink]];
附件:
/cms/uploads/soft/131107/4196-13110G10119.zip原帖:http://www.cocoachina.com/bbs/read.php?tid=123883
- cocoa论坛会员源码分享
- 转载:Cocoa 学习资源分享
- cocoa入门级别的源码
- 源码分享
- Cocoa
- Cocoa
- Cocoa
- Cocoa
- 分享按钮/分享网址 分享源码
- DNotes的源码分享
- EventPullSource源码分享
- 源码分享(一)
- 源码分享(二)
- Android分享功能源码
- 亲测源码分享
- Android 开发源码分享
- Android 开发源码分享
- Android 开发源码分享
- 条件变量
- Google App Engine for java学习笔记
- 计算机著作推荐
- 《程序员》 -- 业务、销售与技术的关系
- git push :推送本地更改到远程仓库的三种模式
- cocoa论坛会员源码分享
- java 从零开始,学习笔记之基础入门<Static>(十二)
- Android开发必看知识,不看后悔
- Twitter的中国门徒:新浪微博何去何从
- 说说Linux下的夏令时问题
- 关于MongoDB在64位服务器上依然报 mmap failed with out of memory 错误的解决方法(附Mysql性能对比测试)
- JPA概要
- Java中Vector和ArrayList的区别
- 技术点