iOS 项目常用方法集

1、改变 UITextField 占位文字 颜色和去掉底部白框

[_userName setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

//去掉底部白框[UIView setAnimationDuration:0.0];28[UIView beginAnimations:nil context:NULL];

2、禁止横屏 在Appdelegate 使用和判断程序是否第一次启动

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

return UIInterfaceOrientationMaskPortrait;

}

//判断程序是否第一次启动

if(![[NSUserDefaultsstandardUserDefaults] boolForKey:@"firstLaunch"]){ [[NSUserDefaultsstandardUserDefaults] setBool:YESforKey:@"firstLaunch"];NSLog(@"第一次启动"); [[NSUserDefaultsstandardUserDefaults] setBool:NOforKey:@"isLogin"]; }else{NSLog(@"已经不是第一次启动了"); }

3、修改状态栏颜色 (默认黑色,修改为白色)

//1.在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO

//2.在需要改变状态栏颜色的 AppDelegate中在 didFinishLaunchingWithOptions 方法中增加:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

//3.如果需要在单个ViewController中添加,在ViewDidLoad方法中增加:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

4、模糊效果

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *test = [[UIVisualEffectView alloc] initWithEffect:effect];

test.frame = self.view.bounds;

test.alpha = 0.5;

[self.view addSubview:test];

5、强制横屏代码

#pragma mark - 强制横屏代码

- (BOOL)shouldAutorotate

{

//是否支持转屏

return NO;

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

//支持哪些转屏方向

return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return UIInterfaceOrientationLandscapeRight;

}

- (BOOL)prefersStatusBarHidden

{

return NO;

}

6、在状态栏显示有网络请求的提示器

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

7、相对路径

$(SRCROOT)/

8、视图是否自动(只是把第一个自动)向下挪64

self.automaticallyAdjustsScrollViewInsets = NO; //不让系统帮咱们把scrollView及其子类的视图向下调整64

9、 隐藏手机的状态栏

-(BOOL)prefersStatusBarHidden {

return YES;

}

10、代理的安全保护【断是否有代理,和代理是否执行了代理方法】

if (self.delegate && [self.delegate respondsToSelector:@selector(passValueWithArray:)]) {

// make you codes

}

11、在ARC工程中导入MRC的类和在MRC工程中导入ARC的类

// 在ARC工程中导入MRC的类  我们选中工程->选中targets中的工程,然后选中Build Phases->在导入的类后边加入标记 -  fno-objc-arc

// 在MRC工程中导入ARC的类 路径与上面一致,在该类后面加上标记 -fobjc-arc

12、通过2D仿射函数实现小的动画效果(变大缩小) --可用于自定义pageControl中

[UIView animateWithDuration:0.3 animations:^{

imageView.transform = CGAffineTransformMakeScale(2, 2);

} completion:^(BOOL finished) {

imageView.transform = CGAffineTransformMakeScale(1.0, 1.0);

}];

13、查看系统所有字体

for (id familyName in [UIFont familyNames]) {

NSLog(@"%@", familyName);

for (id fontName in [UIFont fontNamesForFamilyName:familyName]) NSLog(@"  %@", fontName);

}

14、判断一个字符串是否为数字

NSCharacterSet *notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];

if ([str rangeOfCharacterFromSet:notDigits].location == NSNotFound) {// 是数字

} else {// 不是数字

}

15、将一个view保存为pdf格式

- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename

{

NSMutableData *pdfData = [NSMutableData data];

UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);

UIGraphicsBeginPDFPage();

CGContextRef pdfContext = UIGraphicsGetCurrentContext();

[aView.layer renderInContext:pdfContext];

UIGraphicsEndPDFContext();

NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

NSString* documentDirectory = [documentDirectories objectAtIndex:0];

NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

[pdfData writeToFile:documentDirectoryFilename atomically:YES];

NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);

}

16、让一个view在父视图中心

child.center = [parent convertPoint:parent.center fromView:parent.superview];

17、获取当前导航控制器下前一个控制器

- (UIViewController *)backViewController

{

NSInteger myIndex = [self.navigationController.viewControllers indexOfObject:self];

if ( myIndex != 0 && myIndex != NSNotFound ) {

return [self.navigationController.viewControllers objectAtIndex:myIndex-1];

} else {

return nil;

}

}

18、保存UIImage到本地

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];

[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];

19、键盘上方增加工具栏

UIToolbar *keyboardDoneButtonView = [[UIToolbar alloc] init];

[keyboardDoneButtonView sizeToFit];

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"

style:UIBarButtonItemStyleBordered target:self

action:@selector(doneClicked:)];

[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];

txtField.inputAccessoryView = keyboardDoneButtonView;

20、在image上绘制文字并生成新的image

UIFont *font = [UIFont boldSystemFontOfSize:12];

UIGraphicsBeginImageContext(image.size);

[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];

CGRect rect = CGRectMake(point.x, point.y, image.size.width, image.size.height);

[[UIColor whiteColor] set];

[text drawInRect:CGRectIntegral(rect) withFont:font];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

21、判断一个view是否为另一个view的子视图

// 如果myView是self.view本身,也会返回yes

BOOL isSubView = [myView isDescendantOfView:self.view];

22、判断一个字符串是否包含另一个字符串

// 方法一、这种方法只适用于iOS8之后,如果是配iOS8之前用方法二

if ([str containsString:otherStr]) NSLog(@"包含");

// 方法二

NSRange range = [str rangeOfString:otherStr];

if (range.location != NSNotFound) NSLog(@"包含");

23、判断某一行的cell是否已经显示

CGRect cellRect = [tableView rectForRowAtIndexPath:indexPath];

BOOL completelyVisible = CGRectContainsRect(tableView.bounds, cellRect);

24、让导航控制器pop回指定的控制器

NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];

for (UIViewController *aViewController in allViewControllers) {

if ([aViewController isKindOfClass:[RequiredViewController class]]) {

[self.navigationController popToViewController:aViewController animated:NO];

break;

}

}

25、获取屏幕方向

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if(orientation == 0) //Default orientation

//默认

else if(orientation == UIInterfaceOrientationPortrait)

//竖屏

else if(orientation == UIInterfaceOrientationLandscapeLeft)

// 左横屏

else if(orientation == UIInterfaceOrientationLandscapeRight)

//右横屏

26、UIWebView添加单击手势不响应

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(webViewClick)];

tap.delegate = self;

[_webView addGestureRecognizer:tap];

// 因为webView本身有一个单击手势,所以再添加会造成手势冲突,从而不响应。需要绑定手势代理,并实现下边的代理方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

return YES;

}

27、获取手机RAM容量

// 需要导入#import

mach_port_t host_port;

mach_msg_type_number_t host_size;

vm_size_t pagesize;

host_port = mach_host_self();

host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);

host_page_size(host_port, &pagesize);

vm_statistics_data_t vm_stat;

if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {

NSLog(@"Failed to fetch vm statistics");

}

/* Stats in bytes */

natural_t mem_used = (vm_stat.active_count +

vm_stat.inactive_count +

vm_stat.wire_count) * pagesize;

natural_t mem_free = vm_stat.free_count * pagesize;

natural_t mem_total = mem_used + mem_free;

NSLog(@"已用: %u 可用: %u 总共: %u", mem_used, mem_free, mem_total);

28、地图上两个点之间的实际距离

// 需要导入#import  位置A、B

CLLocation *locA = [[CLLocation alloc] initWithLatitude:34 longitude:113];

CLLocation *locB = [[CLLocation alloc] initWithLatitude:31.05 longitude:121.76];

// CLLocationDistance求出的单位为米

CLLocationDistance distance = [locA distanceFromLocation:locB];

29、在应用中打开设置的某个界面

// 打开设置->通用

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];

// 以下是设置其他界面

prefs:root=General&path=About

prefs:root=General&path=ACCESSIBILITY

prefs:root=AIRPLANE_MODE

prefs:root=General&path=AUTOLOCK

prefs:root=General&path=USAGE/CELLULAR_USAGE

prefs:root=Brightness

prefs:root=Bluetooth

prefs:root=General&path=DATE_AND_TIME

prefs:root=FACETIME

prefs:root=General

prefs:root=General&path=Keyboard

prefs:root=CASTLE

prefs:root=CASTLE&path=STORAGE_AND_BACKUP

prefs:root=General&path=INTERNATIONAL

prefs:root=LOCATION_SERVICES

prefs:root=ACCOUNT_SETTINGS

prefs:root=MUSIC

prefs:root=MUSIC&path=EQ

prefs:root=MUSIC&path=VolumeLimit

prefs:root=General&path=Network

prefs:root=NIKE_PLUS_IPOD

prefs:root=NOTES

prefs:root=NOTIFICATIONS_ID

prefs:root=Phone

prefs:root=Photos

prefs:root=General&path=ManagedConfigurationList

prefs:root=General&path=Reset

prefs:root=Sounds&path=Ringtone

prefs:root=Safari

prefs:root=General&path=Assistant

prefs:root=Sounds

prefs:root=General&path=SOFTWARE_UPDATE_LINK

prefs:root=STORE

prefs:root=TWITTER

prefs:root=FACEBOOK

prefs:root=General&path=USAGE prefs:root=VIDEO

prefs:root=General&path=Network/VPN

prefs:root=Wallpaper

prefs:root=WIFI

prefs:root=INTERNET_TETHERING

prefs:root=Phone&path=Blocked

prefs:root=DO_NOT_DISTURB

30、监听scrollView是否滚动到了顶部/底部

-(void)scrollViewDidScroll: (UIScrollView*)scrollView

{

float scrollViewHeight = scrollView.frame.size.height;

float scrollContentSizeHeight = scrollView.contentSize.height;

float scrollOffset = scrollView.contentOffset.y;

if (scrollOffset == 0)

{

// 滚动到了顶部

}

else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)

{

// 滚动到了底部

}

}

31、从导航控制器中删除某个控制器

// 方法一、知道这个控制器所处的导航控制器下标

NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];

[navigationArray removeObjectAtIndex: 2];

self.navigationController.viewControllers = navigationArray;

// 方法二、知道具体是哪个控制器

NSArray* tempVCA = [self.navigationController viewControllers];

for(UIViewController *tempVC in tempVCA)

{

if([tempVC isKindOfClass:[urViewControllerClass class]])

{

[tempVC removeFromParentViewController];

}

}

32、触摸事件类型

UIControlEventTouchCancel 取消控件当前触发的事件

UIControlEventTouchDown 点按下去的事件

UIControlEventTouchDownRepeat 重复的触动事件

UIControlEventTouchDragEnter 手指被拖动到控件的边界的事件

UIControlEventTouchDragExit 一个手指从控件内拖到外界的事件

UIControlEventTouchDragInside 手指在控件的边界内拖动的事件

UIControlEventTouchDragOutside 手指在控件边界之外被拖动的事件

UIControlEventTouchUpInside 手指处于控制范围内的触摸事件

UIControlEventTouchUpOutside 手指超出控制范围的控制中的触摸事件

33、比较两个UIImage是否相等

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2

{

NSData *data1 = UIImagePNGRepresentation(image1);

NSData *data2 = UIImagePNGRepresentation(image2);

return [data1 isEqual:data2];

}

34、代码方式调整屏幕亮度

// brightness属性值在0-1之间,0代表最小亮度,1代表最大亮度

[[UIScreen mainScreen] setBrightness:0.5];

35、根据经纬度获取城市等信息

// 创建经纬度

CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

//创建一个译码器

CLGeocoder *cLGeocoder = [[CLGeocoder alloc] init];

[cLGeocoder reverseGeocodeLocation:userLocation completionHandler:^(NSArray *placemarks, NSError *error) {

CLPlacemark *place = [placemarks objectAtIndex:0];

// 位置名

NSLog(@"name,%@",place.name);

// 街道

NSLog(@"thoroughfare,%@",place.thoroughfare);

// 子街道

NSLog(@"subThoroughfare,%@",place.subThoroughfare);

// 市

NSLog(@"locality,%@",place.locality);

// 区

NSLog(@"subLocality,%@",place.subLocality);

// 国家

NSLog(@"country,%@",place.country);

}

}];

36、如何防止添加多个NSNotification观察者?

// 解决方案就是添加观察者之前先移除下这个观察者

[[NSNotificationCenter defaultCenter] removeObserver:observer name:name object:object];

[[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:name object:object];

37、处理字符串,使其首字母大写

NSString *str = @"abcdefghijklmn";

NSString *resultStr;

if (str && str.length > 0) {

resultStr = [str stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[str substringToIndex:1] capitalizedString]];

}

NSLog(@"%@", resultStr);

38、获取字符串中的数字

- (NSString *)getNumberFromStr:(NSString *)str

{

NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];

return [[str componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];

}

39、为UIView的某个方向添加边框

- (void)wzb_addBorder:(WZBBorderDirectionType)direction color:(UIColor *)color width:(CGFloat)width

{

CALayer *border = [CALayer layer];

border.backgroundColor = color.CGColor;

switch (direction) {

case WZBBorderDirectionTop:

{

border.frame = CGRectMake(0.0f, 0.0f, self.bounds.size.width, width);

}

break;

case WZBBorderDirectionLeft:

{

border.frame = CGRectMake(0.0f, 0.0f, width, self.bounds.size.height);

}

break;

case WZBBorderDirectionBottom:

{

border.frame = CGRectMake(0.0f, self.bounds.size.height - width, self.bounds.size.width, width);

}

break;

case WZBBorderDirectionRight:

{

border.frame = CGRectMake(self.bounds.size.width - width, 0, width, self.bounds.size.height);

}

break;

default:

break;

}

[self.layer addSublayer:border];

}

40、自动搜索功能,用户连续输入的时候不搜索,用户停止输入的时候自动搜索(我这里设置的是0.5s,可根据需求更改)

// 输入框文字改变的时候调用

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{

// 先取消调用搜索方法

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(searchNewResult) object:nil];

// 0.5秒后调用搜索方法

[self performSelector:@selector(searchNewResult) withObject:nil afterDelay:0.5];

}

41、修改UISearchBar的占位文字颜色

// 方法一(推荐使用)

UITextField *searchField = [searchBar valueForKey:@"_searchField"];

[searchField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];

// 方法二(已过期)

[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];

// 方法三(已过期)

NSDictionary *placeholderAttributes = @{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:15],};

NSAttributedString *attributedPlaceholder = [[NSAttributedString alloc] initWithString:searchBar.placeholder attributes:placeholderAttributes];

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setAttributedPlaceholder:attributedPlaceholder];

42、动画执行removeFromSuperview

[UIView animateWithDuration:0.2

animations:^{

view.alpha = 0.0f;

} completion:^(BOOL finished){

[view removeFromSuperview];

}];

43、修改image颜色

UIImage *image = [UIImage imageNamed:@"test"];

imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextClipToMask(context, rect, image.CGImage);

CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);

CGContextFillRect(context, rect);

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored];

imageView.image = flippedImage;

44、利用runtime获取一个类所有属性

- (NSArray *)allPropertyNames:(Class)aClass

{

unsigned count;

objc_property_t *properties = class_copyPropertyList(aClass, &count);

NSMutableArray *rv = [NSMutableArray array];

unsigned i;

for (i = 0; i < count; i++)

{

objc_property_t property = properties[i];

NSString *name = [NSString stringWithUTF8String:property_getName(property)];

[rv addObject:name];

}

free(properties);

return rv;

}

45、让push跳转动画像modal跳转动画那样效果(从下往上推上来)

- (void)push

{

TestViewController *vc = [[TestViewController alloc] init];

vc.view.backgroundColor = [UIColor redColor];

CATransition* transition = [CATransition animation];

transition.duration = 0.4f;

transition.type = kCATransitionMoveIn;

transition.subtype = kCATransitionFromTop;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

[self.navigationController pushViewController:vc animated:NO];

}

- (void)pop

{

CATransition* transition = [CATransition animation];

transition.duration = 0.4f;

transition.type = kCATransitionReveal;

transition.subtype = kCATransitionFromBottom;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

[self.navigationController popViewControllerAnimated:NO];

}

46.cell默认选中方法

[self selectIndexPath:[LrdIndexPath indexPathWithColumn:0 row:0]];

47.实现代码只让执行一次

static dispatch_once_t hanwanjie;

dispatch_once(&hanwanjie, ^{

NSLog(@"123456789");

});

48.数组用系统方法compare做字母的简单排序

NSArray *oldArray = @[@"bac",@"bzd",@"azc",@"azz"];

NSArray *newArray = [oldArray sortedArrayUsingSelector:@selector(compare:)];

NSLog(@"new array = %@",newArray);

NSMutableArray *pArrayS = [NSMutableArray arrayWithCapacity:0];//根据下标开始

49.快速遍历方法

for (MJAppMapListModel*model in array) {

NSLog(@"1 =%@ 2 =%@ 3 =%@ 4 =%@ 5 =%@ 6 =%@",model.id,model.menuTitle,model.menuTip,model.urlInterface,model.menuIconPath,model.urlParams);

}

for (NSString *categoryId in sortedArray) {

NSLog(@"[dict objectForKey:categoryId] === %@",[dict objectForKey:categoryId]);

}

for (NSString *str in [dict allKeys]) {

NSLog(@"key == %@",str);

}

50.//在主线程和子线程延迟执行

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self delayDo:@"GCD"];

});

//在子线程延迟执行

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

[self delayDo:@"Global-GCD"];

});

51.//获取cell上按钮的下标

[cell.ButtonIphone addTarget:self action:@selector(btAction:) forControlEvents:UIControlEventTouchUpInside];

-(void)btAction:(UIButton*)btn

{

CGPoint point = btn.center;

point = [self.tableView convertPoint:point fromView:btn.superview];

NSIndexPath* indexpath = [self.tableView indexPathForRowAtPoint:point];

NSLog(@"dhajhdjashdjashdj == %@",indexpath);

NSLog(@"我是你点击section第 %ld行",(long)[indexpath section]);

NSLog(@"我是你点击row第 %ld行",(long)[indexpath row]);

}

52.//过滤为空的cell

_tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

53.设置文字和图片一起的使用(富文本)

- (NSAttributedString *)stringWithUIImage:(NSString *) contentStr {

// 创建一个富文本

NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentStr];

//// 修改富文本中的不同文字的样式

//[attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, 5)];

//[attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 5)];

/**

添加图片到指定的位置

*/

//NSTextAttachment *attchImage = [[NSTextAttachment alloc] init];

//// 表情图片

//attchImage.image = [UIImage imageNamed:@"jiedu"];

//// 设置图片大小

//attchImage.bounds = CGRectMake(0, 0, 40, 15);

//NSAttributedString *stringImage = [NSAttributedString attributedStringWithAttachment:attchImage];

//[attriStr insertAttributedString:stringImage atIndex:2];

// 设置数字为红色

/*

[attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 9)];

[attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(5, 9)];

*/

//NSDictionary * attrDict = @{ NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15],

// NSForegroundColorAttributeName: [UIColor blueColor] };

//创建 NSAttributedString 并赋值

//_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict];

//NSDictionary * attriBute = @{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:30]};

//[attriStr addAttributes:attriBute range:NSMakeRange(5, 9)];

// 添加表情到最后一位

NSTextAttachment *attch = [[NSTextAttachment alloc] init];

// 表情图片

attch.image = [UIImage imageNamed:@"bg_update_tips"];

// 设置图片大小

attch.bounds = CGRectMake(0, 0, 40, 15);

// 创建带有图片的富文本

NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];

[attriStr appendAttributedString:string];

return attriStr;

}

54.//判断数组包含有没有字符串

if ([_MutaArrayAAA containsObject:cell.Label.text])

55.//删除数组包含另外对象属性值

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@",p.name];

NSArray *filteredArray = [self.SaveTheData filteredArrayUsingPredicate:predicate];

[self.SaveTheData removeObjectsInArray:filteredArray];

56.监听UITableView的上下拉

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if(scrollView.contentOffset.y < 0){

NSLog(@"top*****下");

}else if(scrollView.contentOffset.y > 0){

NSLog(@"bottom*****上");

}

}

57.//直接返回根目录

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];

[self.navigationController popToRootViewControllerAnimated:YES]; 返回上一级

//返回指定界面

1.int INPAGE =(int)self. navigationController.viewControllers.count-2;

TheEditorViewController*vc = self.navigationController.viewControllers[INPAGE];

[self.navigationController popToViewController:vc animated:YES];

2.CustomerContactViewController * getmoney = nil;

for (UIViewController * VC in self.navigationController.viewControllers) {

if ([VC isKindOfClass:[CustomerContactViewController class]]) {

getmoney = (CustomerContactViewController *)VC;

}

}

[self.navigationController popToViewController:getmoney animated:YES];

58.APP启动界面的动画

UIImageView *welcome = [[UIImageView alloc]initWithFrame:_window.bounds];

[welcome setImage:[UIImage imageNamed:@"HJLaunchImage"]];

//把背景图放在最上层

[_window addSubview:welcome];

[_window bringSubviewToFront:welcome];

welcome.alpha = 0.99;//这里alpha的值和下面alpha的值不能设置为相同的,否则动画相当于瞬间执行完,启动页之后动画瞬间消失。这里alpha设为0.99,动画就不会有一闪而过的效果,而是一种类似于静态背景的效果。设为0,动画就相当于是淡入的效果了。

[UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{

CGRect frame = welcome.frame;

frame.size.width = _window.size.width*1.3;

frame.size.height = _window.size.height*1.3;

welcome.frame = frame;

welcome.center = _window.center;

welcome.alpha = 0;

} completion:^(BOOL finished) {

[welcome removeFromSuperview];

}];

59.数组转字典化

for(NSMutableDictionary *dic in responseObject[@"data"])

{

vc.remindTapge = 5;

vc.dicData =dic;

}

60.数组字符串

NSMutableString *detailAddress = [[NSMutableString alloc] init];

if (self.index1 < self.provinceArr.count) {

NSString *firstAddress = self.provinceArr[self.index1];

[detailAddress appendString:firstAddress];//拼接字符串

}

61.//计算时间差0年0月1日1小时51分钟55秒

// 1.确定时间

NSString *time1 = @"2015-09-8 10:18:15";

NSString *time2 = @"2015-09-9 12:10:10";

// 2.将时间转换为date

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";

NSDate *date1 = [formatter dateFromString:time1];

NSDate *date2 = [formatter dateFromString:time2];

// 3.创建日历

NSCalendar *calendar = [NSCalendar currentCalendar];

NSCalendarUnit type = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

// 4.利用日历对象比较两个时间的差值

NSDateComponents *cmps = [calendar components:type fromDate:date1 toDate:date2 options:0];

// 5.输出结果

NSLog(@"两个时间相差%ld年%ld月%ld日%ld小时%ld分钟%ld秒", cmps.year, cmps.month, cmps.day, cmps.hour, cmps.minute, cmps.second);

62.//数组保存对象的方法

[self.SaveTheData addObject: @{

@"name":p.name,

@"phoneNumber":phoneNumber

}];

63.//关闭WebView播放音频或者视频退出时停止音频后台播放

[self.WKWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];

64.//监听原生点击返回按钮

-(void)viewDidDisappear:(BOOL)animated

{

}

65.//UITableView和UICollectionView获取已分配的单元格cell

//UICollectionView

HomeViewCollectionViewCell * cell = (HomeViewCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];

//UITableView

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];

NSString *resuID =[NSString stringWithFormat:@"inputCell_%ld",(long)indexPath.row];

InputTableViewCell *inpCell = [self.tableView dequeueReusableCellWithIdentifier:resuID];

66.在Appdelegate.m中的didFinishLaunchingWithOptions

方法中添加如下代码,就全局搞定了!

if (@available(ios 11.0,*))

{

UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

UITableView.appearance.estimatedRowHeight = 0;

UITableView.appearance.estimatedSectionFooterHeight = 0;

UITableView.appearance.estimatedSectionHeaderHeight = 0;

}

67.数据存储3种方式:

1.writeToFile

//1.1 你需要获取路径

NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

// .XXX 尾椎 只是决定 以哪中方式查看数据, 对存入的数据本身没有影响

NSString *fiflePath = [path stringByAppendingPathComponent:@"data.XXX"];

//1.2 写数据

NSArray *dataArray = @[@"1",@"2",@"3",@"霜4"];      //atomically 原子性的,数据安全的, 百分之九十九都是YES

[dataArray writeToFile:fiflePath atomically:YES];

//1.读取路径

NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

NSString *fiflePath = [path stringByAppendingPathComponent:@"data.XXX"];

//2.取出来

NSArray *dataArray = [NSArray arrayWithContentsOfFile:fiflePath];

2.userDefault(偏好设置)

//1. 获取系统的偏好设置对象

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

//2. 存储数据

[defaults setObject:@"小明" forKey:@"name"];

[defaults setInteger:100 forKey:@"age"];

[defaults setBool:NO forKey:@"isTrue"];

//3.立即同步:  强制写入

[defaults synchronize];

//1.获取读取数据到偏好设置的路径

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

//2.读取数据

NSString *name =  [defaults objectForKey:@"name"];

NSInteger age = [defaults integerForKey:@"age"];

BOOL isTrue = [defaults boolForKey:@"isTrue"];

3.归档

//1.文件路径

NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"PsersonData.plist"];

//1. 有个对象

Pserson *pser = [[Pserson alloc]init];

pser.name = @"小小麦";

pser.age = 12;

pser.sex = YES;

//2.存储  归档

[NSKeyedArchiver archiveRootObject:p toFile:filePath];


//读取数据反归档 ,解档

NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"data.plist"];

CZPserson *p = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];

68.动画:

1.基础动画:

//基础动画(缩放)

MTBasicAnimation* basic1 = [MTBasicAnimation animationWithKeyPath:@"transform.scale"];

basic1.toValue = @(0.1);

//基础动画(旋转)

MTBasicAnimation* basic2 = [MTBasicAnimation animationWithKeyPath:@"transform.rotation"];

basic2.toValue = @(M_PI*2);

2.关键帧动画:

//创建路径

UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:150 startAngle:0 endAngle:M_PI*2 clockwise:YES];

MTKeyframeAnimation* key = [MTKeyframeAnimation animationWithKeyPath:@"position"];

key.path = path.CGPath;

3.转场动画:

//3.添加转场动画

MTTransition *sition = [MTTransition animation];

//设置属性

//样式

sition.type = kMTTransitionMoveIn;

//方向

sition.subtype = kMTTransitionFromBottom;

//添加动画

[self.myImageView.layer addAnimation:sition forKey:nil];

4.组动画:

//创建路径

UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:150 startAngle:0 endAngle:M_PI*2 clockwise:YES];

//创建组动画

MTAnimationGroup* group = [MTAnimationGroup animation];

//创建动画1,关键帧动画

MTKeyframeAnimation* key = [MTKeyframeAnimation animationWithKeyPath:@"position"];

key.path = path.CGPath;

//创建动画2,基础动画(缩放)

MTBasicAnimation* basic1 = [MTBasicAnimation animationWithKeyPath:@"transform.scale"];

basic1.toValue = @(0.1);

//创建动画3,基础动画(旋转)

MTBasicAnimation* basic2 = [MTBasicAnimation animationWithKeyPath:@"transform.rotation"];

basic2.toValue = @(M_PI*2);

//设置组动画

group.animations = @[key,basic1,basic2];

group.duration = 2.0;

group.repeatCount = 10;

[self.myLayer addAnimation:group forKey:nil];

69.裁剪图片

//1.裁剪区域

CGRect rect = CGRectMake(x, y, w, h);

// 2.调用系统的裁剪方法裁剪图片

/*        参数:        1.被裁剪的大图 CG类型        2.需要裁剪的区域    */

CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, rect);

// 转换成UIImage

UIImage *img = [UIImage imageWithCGImage:imageRef];

// 释放imageRef

CGImageRelease(imageRef);

70.传递事件,判断当前点是否在一个区域内

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

// 1.描述一下按钮上部分的区域

CGRect rect = CGRectMake(0, 0, self.bounds.size.width, 100);

// 2.判断当前点击的点在不在上部分(如果不在,就直接返回nil)

if (!CGRectContainsPoint(rect, point)) {

return nil;

}

// 3.继续传递事件

return [super hitTest:point withEvent:event];

}

71.H5的WebView链接加载的url中文和特殊字符转码

- (NSString *)generateUrl:(NSString *)url{

/**    第一个参数:NULL    第二个参数:C语言的字符串    第三个参数:NULL    第四个参数:要转义的字符串,不要乱转    第五个参数:编码    */

NSString *encodedString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(

NULL,(__bridge CFStringRef)url,NULL,CFSTR("+"),CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));

return encodedString;

}

72.数据加密和解压缩文件

1.base64加密

//加密:

- (NSString *)base64Encode:(NSString *)originalString{

//1.将originalString转成二进制

NSData *data =  [originalString dataUsingEncoding:NSUTF8StringEncoding];

//2.需要将二进制转成Base64加密之后的字符串

return [data base64EncodedStringWithOptions:0];

}

//解密:

- (NSString *)base64Decode:(NSString *)base64String{

//1.Base64加密之后的字符串转成 NSData

NSData *data = [[NSData alloc] initWithBase64EncodedString:base64String options:0];

//2.将二进制转在字符串

NSString *originalString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

return originalString;

}

1.解压缩文件

//下载完毕解压到当前文件夹

[SSZipArchive unzipFileAtPath:location.path toDestination:self.destinationPath uniqueId:nil];

73.计算磁盘大小

1.磁盘总空间大小

+ (CGFloat)diskOfAllSizeMBytes{

CGFloat size = 0.0;

NSError *error;

NSDictionary *dic = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];

if (error) {

#ifdef DEBUG

NSLog(@"error: %@", error.localizedDescription);

#endif

}else{

NSNumber *number = [dic objectForKey:NSFileSystemSize];

size = [number floatValue]/1024/1024;

}

return size;

}

2.磁盘可用空间大小

+ (CGFloat)diskOfFreeSizeMBytes{

CGFloat size = 0.0;

NSError *error;

NSDictionary *dic = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];

if (error) {

#ifdef DEBUG

NSLog(@"error: %@", error.localizedDescription);

#endif

}else{

NSNumber *number = [dic objectForKey:NSFileSystemFreeSize];

size = [number floatValue]/1024/1024;

}

return size;

}

74.信息验证

1.判断手机号码格式是否正确,利用正则表达式验证

+ (BOOL)isMobileNumber:(NSString *)mobileNum{

if (mobileNum.length != 11) {

return NO;

}

/** * 手机号码:

* 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9]

* 移动号段:

134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705

* 联通号段: 130,131,132,155,156,185,186,145,176,1709

* 电信号段: 133,153,180,181,189,177,1700 *

/ NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|70)\d{8}$";

/**

* 中国移动:China Mobile * 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705 */

NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\d{8}$)|(^1705\d{7}$)";

/** * 中国联通:China Unicom * 130,131,132,155,156,185,186,145,176,1709 */

NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\d{8}$)|(^1709\d{7}$)";

/**

* 中国电信:China Telecom * 133,153,180,181,189,177,1700 */ NSString *CT = @"(^1(33|53|77|8[019])\d{8}$)|(^1700\d{7}$)";

NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

if (([regextestmobile evaluateWithObject:mobileNum] == YES) || ([regextestcm evaluateWithObject:mobileNum] == YES) || ([regextestct evaluateWithObject:mobileNum] == YES) || ([regextestcu evaluateWithObject:mobileNum] == YES))

{

return YES;

} else {

return NO;

}

}

2. 判断邮箱格式是否正确,利用正则表达式验证

+ (BOOL)isAvailableEmail:(NSString *)email{

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:email];

}

3. 判断字符串中是否含有空格

+ (BOOL)isHaveSpaceInString:(NSString *)string{

NSRange _range = [string rangeOfString:@" "];

if (_range.location != NSNotFound) {

return YES;

}else {

return NO;

}

}

4. 判断字符串中是否含有中文

+ (BOOL)isHaveChineseInString:(NSString *)string{

for(NSInteger i = 0; i < [string length]; i++){

int a = [string characterAtIndex:i];

if (a > 0x4e00 && a < 0x9fff) {

return YES;

}

}

return NO;

}

5.判断身份证格式

+ (BOOL)checkIdentityCardNo:(NSString*)value {

value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSInteger length =0;

if (!value) {

return NO;

}else {

length = value.length;

if (length !=15 && length !=18) {

return NO;

}

}

// 省份代码

NSArray *areasArray =@[@"11",@"12", @"13",@"14", @"15",@"21", @"22",@"23", @"31",@"32", @"33",@"34", @"35",@"36", @"37",@"41", @"42",@"43", @"44",@"45", @"46",@"50", @"51",@"52", @"53",@"54", @"61",@"62", @"63",@"64", @"65",@"71", @"81",@"82", @"91"];

NSString *valueStart2 = [value substringToIndex:2];

BOOL areaFlag =NO;

for (NSString *areaCode in areasArray) {

if ([areaCode isEqualToString:valueStart2]) {

areaFlag =YES;

break;

}

}

if (!areaFlag) {

return false;

}

NSRegularExpression *regularExpression;

NSUInteger numberofMatch;

NSInteger year =0;

switch (length) {

case 15:

year = [[value substringWithRange:NSMakeRange(6,2)] integerValue] +1900;

if (year %4 ==0 || (year 0 ==0 && year %4 ==0)) {

regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$"

options:NSRegularExpressionCaseInsensitive

error:nil];//测试出生日期的合法性

}else {

regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$"

options:NSRegularExpressionCaseInsensitive

error:nil];//测试出生日期的合法性

}

numberofMatch = [regularExpression numberOfMatchesInString:value                                                options:NSMatchingReportProgress

range:NSMakeRange(0, value.length)];

if(numberofMatch >0) {

return YES;

}else {

return NO;

}

case 18:

year = [value substringWithRange:NSMakeRange(6,4)].intValue;

if (year %4 ==0 || (year 0 ==0 && year %4 ==0)) {

regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$"

options:NSRegularExpressionCaseInsensitive                                                                    error:nil];//测试出生日期的合法性

}else {

regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$"                                                                      options:NSRegularExpressionCaseInsensitive                                                                    error:nil];//测试出生日期的合法性

}

numberofMatch = [regularExpression numberOfMatchesInString:value                                                options:NSMatchingReportProgress                                                    range:NSMakeRange(0, value.length)];

if(numberofMatch >0) {

int S = ([value substringWithRange:NSMakeRange(0,1)].intValue + [value substringWithRange:NSMakeRange(10,1)].intValue) *7 + ([value substringWithRange:NSMakeRange(1,1)].intValue + [value substringWithRange:NSMakeRange(11,1)].intValue) *9 + ([value substringWithRange:NSMakeRange(2,1)].intValue + [value substringWithRange:NSMakeRange(12,1)].intValue) *10 + ([value substringWithRange:NSMakeRange(3,1)].intValue + [value substringWithRange:NSMakeRange(13,1)].intValue) *5 + ([value substringWithRange:NSMakeRange(4,1)].intValue + [value substringWithRange:NSMakeRange(14,1)].intValue) *8 + ([value substringWithRange:NSMakeRange(5,1)].intValue + [value substringWithRange:NSMakeRange(15,1)].intValue) *4 + ([value substringWithRange:NSMakeRange(6,1)].intValue + [value substringWithRange:NSMakeRange(16,1)].intValue) *2 + [value substringWithRange:NSMakeRange(7,1)].intValue *1 + [value substringWithRange:NSMakeRange(8,1)].intValue *6 + [value substringWithRange:NSMakeRange(9,1)].intValue *3;

int Y = S ;

NSString *M =@"F";

NSString *JYM =@"10X98765432";

M = [JYM substringWithRange:NSMakeRange(Y,1)];// 判断校验位

if ([M isEqualToString:[value substringWithRange:NSMakeRange(17,1)]]) {

return YES;// 检测ID的校验位

}else {

return NO;

}

}else {

return NO;

}

default:

return false;

}

}

75.缓存功能的一些事

//缓存路径

#define CacheFilePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]

//缓存计算

//转换B/KB/MB/GB

+(NSString *)SetCacheSize:(unsigned long long)fileSize{

// 单位

double unit = 1000.0;

// 标签文字

NSString *fileSizeText = nil;

if (fileSize >= pow(unit, 3)) {

// fileSize >= 1GB

fileSizeText = [NSString stringWithFormat:@"%.2fGB", fileSize / pow(unit, 3)];

} else if (fileSize >= pow(unit, 2)) {

// fileSize >= 1MB

fileSizeText = [NSString stringWithFormat:@"%.2fMB", fileSize / pow(unit, 2)];

} else if (fileSize >= unit) {

// fileSize >= 1KB

fileSizeText = [NSString stringWithFormat:@"%.2fKB", fileSize / unit];

} else { // fileSize < 1KB

fileSizeText = [NSString stringWithFormat:@"%zdB", fileSize];

}    return fileSizeText;

}

//清空缓存

+(BOOL)CleanCacheFilePath{

//拿到path路径的下一级目录的子文件夹

NSArray *subPathArr = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:CacheFilePath error:nil];

NSString *filePath = nil;

NSError *error = nil;

for (NSString *subPath in subPathArr)    {

filePath = [CacheFilePath stringByAppendingPathComponent:subPath];

//删除子文件夹        [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];

if (error) {

NSLog(@"%@",error);

continue;

}

}

return YES;

}

//SDWebImage清理缓存

// 清理内存

[[SDImageCache sharedImageCache] clearMemory];

// 清理webview 缓存

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (NSHTTPCookie *cookie in [storage cookies]) {

[storage deleteCookie:cookie];

}

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];

[config.URLCache removeAllCachedResponses];

[[NSURLCache sharedURLCache] removeAllCachedResponses];

// 清理硬盘

[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{

//[MBProgressHUD hideAllHUDsForView:self.view animated:YES];

//[self.tableView reloadData];

}];

后续会继续添加项目会用到的方法总结..........

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,884评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,347评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,435评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,509评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,611评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,837评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,987评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,730评论 0 267
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,194评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,525评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,664评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,334评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,944评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,764评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,997评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,389评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,554评论 2 349

推荐阅读更多精彩内容