厚道的Autolayout及VFL经验分享及代码(会员evangel)

厚道的Autolayout及VFL经验分享及代码(会员evangel)

痛苦了3天研究了一下传说中的autolayout。写了一篇比较浅显易读的autolayout的文章,准备发在cc老家,结果提示有敏感词不许发帖。改了很久也不行。深受打击。放在这里了:

http://blog.csdn.net/mozixiong/article/details/14165391

大家看完这篇应该就能够使用autolayout主要特性完成你的项目了。VFL的介绍学习将会给你带来极大的方便。希望大家不要直接拿code。看完文章有了体会再去跑code。会理解深刻些。xib部分不必纠缠过多。玩积木搬,没啥技术含量。VFL的例子希望能给大家清醒的感觉。

附件:

原帖:http://www.cocoachina.com/bbs/read.php?tid=165821



开机动画(会员qqy620)

上传一个开机动画Demo 

附件:

原帖: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(@"%@", 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 

附件:

原帖:http://www.cocoachina.com/bbs/read.php?tid=134821

解决UITextView的placeholder属性(会员qqy620)  

解决UITextView的placeholder属性,并解决了键盘遮挡问题 

附件:

原帖: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 

附件:

原帖: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]]; 

附件:

原帖:http://www.cocoachina.com/bbs/read.php?tid=123883   

(本文来源:网易新媒体(CocoaChina) )  netease
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值