This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 自定义缓存设置 | |
ASIDownloadCache *imageCache = [[ASIDownloadCache alloc] init]; | |
//设置缓存路径 | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentDirectory = [paths objectAtIndex:0]; | |
[self.imageCache setStoragePath:[documentDirectory stringByAppendingPathComponent:@"resource"]]; | |
[self.imageCache setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy]; | |
[self.imageCache clearCachedResponsesForStoragePolicy:ASICachePermanentlyCacheStoragePolicy]; | |
// 设置请求 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1、同步GET请求 | |
NSURL *url = [NSURL URLWithString:@"http://api.hudong.com/iphonexml.do?type=focus-c"]; NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10]; | |
其中缓存协议是个枚举类型包含: | |
NSURLRequestUseProtocolCachePolicy(基础策略) | |
NSURLRequestReloadIgnoringLocalCacheData(忽略本地缓存) | |
NSURLRequestReturnCacheDataElseLoad(首先使用缓存,如果没有本地缓存,才从原地址下载) | |
NSURLRequestReturnCacheDataDontLoad(使用本地缓存,从不下载,如果本地没有缓存,则请求失败,此策略多用于离线操作) | |
NSURLRequestReloadIgnoringLocalAndRemoteCacheData(无视任何缓存策略,无论是本地的还是远程的,总是从原地址重新下载) | |
NSURLRequestReloadRevalidatingCacheData(如果本地缓存是有效的则不下载,其他任何情况都从原地址重新下载) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableArray *someObject = [NSMutableArray array]; | |
NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject); | |
[someObject addObject:@"foo"]; | |
NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)savePicturefromurl:(NSString *)url path:(NSString *)path imgName:(NSString *)imgName | |
{ | |
UIImage *img=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]; | |
if(path==nil) | |
{ | |
path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:imgName]; | |
} | |
[UIImagePNGRepresentation(image) writeToFile:path atomically:YES]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
G: 公元时代,例如AD公元 | |
yy: 年的后2位 | |
yyyy: 完整年 | |
MM: 月,显示为1-12 | |
MMM: 月,显示为英文月份简写,如 Jan | |
MMMM: 月,显示为英文月份全称,如 Janualy | |
dd: 日,2位数表示,如02 | |
d: 日,1-2位显示,如 2 | |
EEE: 简写星期几,如Sun | |
EEEE: 全写星期几,如Sunday |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//函数描述: string 字数限制 | |
//输入参数:string:要判断的string ;minSize:最小字数限制;maxSize:最大字数限制 | |
//返回值: BOOL:是否超出限制 | |
//备注:一个汉字占两个字符,其他字母占一个字符 | |
+ (BOOL)checkStringSize:(NSString*)string minSize:(int)minSize maxSize:(int)maxSize | |
{ | |
NSString *regex = @"^[\u4e00-\u9fa5]"; | |
int length=[string length]; | |
int currentStringSize=0; | |
for (int i=0;i<length;i++) {//逐步判断string中的每个字符是否为汉字,是,占两个字符,不是,占一个字符 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSDate(Conversion) | |
+ (NSDate *)dateFromString:(NSString *)dateString dateFormat:(NSString *)format; | |
+ (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)format; | |
+ (NSInteger)timeBetweenFrom:(NSDate*)fromDateTime | |
to:(NSDate*)toDateTime | |
withUnit:(NSCalendarUnit)unit; | |
@end | |
@implementation NSDate(Conversion) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//数字加千位分隔符 | |
NSNumber *testNumber = [NSNumber numberWithFloat:0.01f]; | |
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; | |
[numberFormatter setPositiveFormat:@"###,##0.00;"]; | |
NSString *formattedNumberString = [numberFormatter stringFromNumber:testNumber]; | |
NSLog(@"formattedNumberString:%@", formattedNumberString); | |
//formattedNumberString log为1,234,567.89 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIColor(ColorComponents) | |
- (CGColorSpaceModel) colorSpaceModel; | |
- (CGFloat) red; | |
- (CGFloat) green; | |
- (CGFloat) blue; | |
- (CGFloat) alpha; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//把view截图为UIImage | |
- (UIImage *)renderInImage:(UIView *)view | |
{ | |
UIGraphicsBeginImageContext(view.bounds.size); | |
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return (img); | |
} |