标签:nsdata 删除 lstat bar phone lin change 程序 复杂
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setSeparatorInset:UIEdgeInsetsZero]; [cell setLayoutMargins:UIEdgeInsetsZero]; cell.preservesSuperviewLayoutMargins = NO; } - (void)viewDidLayoutSubviews { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; [self.tableView setLayoutMargins:UIEdgeInsetsZero]; }
dispatch_group_t group = dispatch_group_create(); dispatch_queue_t serialQueue = dispatch_queue_create("com.wzb.test.www", DISPATCH_QUEUE_SERIAL); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求一 [WebClick getDataSuccess:^(ResponseModel *model) { dispatch_group_leave(group); } failure:^(NSString *err) { dispatch_group_leave(group); }]; }); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求二 [WebClick getDataSuccess:getBigTypeRM onSuccess:^(ResponseModel *model) { dispatch_group_leave(group); } failure:^(NSString *errorString) { dispatch_group_leave(group); }]; }); dispatch_group_enter(group); dispatch_group_async(group, serialQueue, ^{ // 网络请求三 [WebClick getDataSuccess:^{ dispatch_group_leave(group); } failure:^(NSString *errorString) { dispatch_group_leave(group); }]; }); // 所有网络请求结束后会来到这个方法 dispatch_group_notify(group, serialQueue, ^{ dispatch_async(dispatch_get_global_queue(0, 0), ^{ dispatch_async(dispatch_get_main_queue(), ^{ // 刷新UI }); }); });
id PersonClass = objc_getClass("Person"); unsigned int outCount, i; objc_property_t *properties = class_copyPropertyList(PersonClass, &outCount); for (i = 0; i < outCount; i++) { objc_property_t property = properties[i]; fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property)); }
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // app名称 NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; // app版本 NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; // app build版本 NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"]; //手机序列号 NSString* identifierNumber = [[UIDevice currentDevice] uniqueIdentifier]; NSLog(@"手机序列号: %@",identifierNumber); //手机别名: 用户定义的名称 NSString* userPhoneName = [[UIDevice currentDevice] name]; NSLog(@"手机别名: %@", userPhoneName); //设备名称 NSString* deviceName = [[UIDevice currentDevice] systemName]; NSLog(@"设备名称: %@",deviceName ); //手机系统版本 NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; NSLog(@"手机系统版本: %@", phoneVersion); //手机型号 NSString* phoneModel = [[UIDevice currentDevice] model]; NSLog(@"手机型号: %@",phoneModel ); //地方型号 (国际化区域名称) NSString* localPhoneModel = [[UIDevice currentDevice] localizedModel]; NSLog(@"国际化区域名称: %@",localPhoneModel ); NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; // 当前应用名称 NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; NSLog(@"当前应用名称:%@",appCurName); // 当前应用软件版本 比如:1.0.1 NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; NSLog(@"当前应用软件版本:%@",appCurVersion); // 当前应用版本号码 int类型 NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"]; NSLog(@"当前应用版本号码:%@",appCurVersionNum);
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
#define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
#define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
+ (UIImage *)creatImageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
- (CGFloat)getCachSize { NSUInteger imageCacheSize = [[SDImageCache sharedImageCache] getSize]; //获取自定义缓存大小 //用枚举器遍历 一个文件夹的内容 //1.获取 文件夹枚举器 NSString *myCachePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]; NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:myCachePath]; __block NSUInteger count = 0; //2.遍历 for (NSString *fileName in enumerator) { NSString *path = [myCachePath stringByAppendingPathComponent:fileName]; NSDictionary *fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; count += fileDict.fileSize;//自定义所有缓存大小 } // 得到是字节 转化为M CGFloat totalSize = ((CGFloat)imageCacheSize+count)/1024/1024; return totalSize; }
- (void)handleClearView { //删除两部分 //1.删除 sd 图片缓存 //先清除内存中的图片缓存 [[SDImageCache sharedImageCache] clearMemory]; //清除磁盘的缓存 [[SDImageCache sharedImageCache] clearDisk]; //2.删除自己缓存 NSString *myCachePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]; [[NSFileManager defaultManager] removeItemAtPath:myCachePath error:nil]; }
方法一: NSArray * arr1 = @[@1,@2,@3]; NSArray * arr2 = @[@2,@3,@4,@5]; NSPredicate * filterPredicate = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)",arr1]; NSArray * filter = [arr2 filteredArrayUsingPredicate:filterPredicate]; NSLog(@"%@",filter); 方法二: NSArray *newArr = [oldArr valueForKeyPath:@“@distinctUnionOfObjects.self"];
NSLog(@"%%"); NSLog(@"\"");
if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) { NSLog(@"没有定位权限"); } AVAuthorizationStatus statusVideo = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (statusVideo == AVAuthorizationStatusDenied) { NSLog(@"没有摄像头权限"); } //是否有麦克风权限 AVAuthorizationStatus statusAudio = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; if (statusAudio == AVAuthorizationStatusDenied) { NSLog(@"没有录音权限"); } [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if (status == PHAuthorizationStatusDenied) { NSLog(@"没有相册权限"); } }];
+ (UIImage *)resizableImage:(NSString *)imageName { UIImage *image = [UIImage imageNamed:imageName]; CGFloat imageW = image.size.width; CGFloat imageH = image.size.height; return [image resizableImageWithCapInsets:UIEdgeInsetsMake(imageH * 0.5, imageW * 0.5, imageH * 0.5, imageW * 0.5) resizingMode:UIImageResizingModeStretch]; }
+ (NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString { NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil]; return responseJSON; }
// 方法1 if ([str1 containsString:str2]) { NSLog(@"str1包含str2"); } else { NSLog(@"str1不包含str2"); } // 方法2 if ([str1 rangeOfString: str2].location == NSNotFound) { NSLog(@"str1不包含str2"); } else { NSLog(@"str1包含str2"); }
cell.selectionStyle = UITableViewCellSelectionStyleNone;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; }
+ (BOOL)isBlank:(NSString *)str { NSRange _range = [str rangeOfString:@" "]; if (_range.location != NSNotFound) { //有空格 return YES; } else { //没有空格 return NO; } }
+ (NSString *)removeSpaceAndNewline:(NSString *)str { NSString *temp = [str stringByReplacingOccurrencesOfString:@" " withString:@""]; temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""]; temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""]; return temp; }
1、把需要改的约束Constraint拖条线出来,成为属性 2、在需要动画的地方加入代码,改变此属性的constant属性 3、开始做UIView动画,动画里边调用layoutIfNeeded方法 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonTopConstraint; self.buttonTopConstraint.constant = 100; [UIView animateWithDuration:.5 animations:^{ [self.view layoutIfNeeded]; }];
//方法一 NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; //方法二 - (void)resetDefaults { NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; NSDictionary * dict = [defs dictionaryRepresentation]; for (id key in dict) { [defs removeObjectForKey:key]; } [defs synchronize]; } // 方法三 [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor redColor]; [cell setSelectedBackgroundView:bgColorView];
1、init方法不会调用 2、addSubview方法等时候会调用 3、bounds改变的时候调用 4、scrollView滚动的时候会调用scrollView的layoutSubviews方法(所以不建议在scrollView的layoutSubviews方法中做复杂逻辑) 5、旋转设备的时候调用 6、子视图被移除的时候调用
[segment setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0f]} forState:UIControlStateNormal];
// view分类方法 - (UIViewController *)belongViewController { for (UIView *next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return (UIViewController *)nextResponder; } } return nil; }
- (NSString *)encodeToBase64String:(UIImage *)image { return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; } - (UIImage *)decodeBase64ToImage:(NSString *)strEncodeData { NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters]; return [UIImage imageWithData:data]; }
[self.tableView setSeparatorColor:[UIColor redColor]];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIImage *icon = [UIImage imageNamed:@""]; CGSize itemSize = CGSizeMake(30, 30); UIGraphicsBeginImageContextWithOptions(itemSize, NO ,0.0); CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); [icon drawInRect:imageRect]; cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString:label.text]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setLineSpacing:20]; [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, label.text.length)]; label.attributedText = attrString;
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:label.text]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)]; label.attributedText = string;
NSDate* date1 = someDate; NSDate* date2 = someOtherDate; NSTimeInterval distanceBetweenDates = [date1 timeIntervalSinceDate:date2]; double secondsInAnHour = 3600; // 除以3600是把秒化成小时,除以60得到结果为相差的分钟数 NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;
// 自定义cell,重写setFrame:方法 - (void)setFrame:(CGRect)frame { frame.size.height -= 20; [super setFrame:frame]; }
推荐使用这个框架 FLAnimatedImage
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"]; [UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]]; for (UIViewController *aViewController in allViewControllers) { if ([aViewController isKindOfClass:[RequiredViewController class]]) { [self.navigationController popToViewController:aViewController animated:NO]; } }
// 需要导入#import <CoreLocation/CoreLocation.h> CLLocation *locA = [[CLLocation alloc] initWithLatitude:34 longitude:113]; CLLocation *locB = [[CLLocation alloc] initWithLatitude:31.05 longitude:121.76]; // CLLocationDistance求出的单位为米 CLLocationDistance distance = [locA distanceFromLocation:locB];
// 我们一般用这个方法处理stringByAddingPercentEscapesUsingEncoding但是这个方法好想不会处理/和&这种特殊符号,这种情况就需要用下边这个方法处理 @implementation NSString (NSString_Extended) - (NSString *)urlencode { NSMutableString *output = [NSMutableString string]; const unsigned char *source = (const unsigned char *)[self UTF8String]; int sourceLen = strlen((const char *)source); for (int i = 0; i < sourceLen; ++i) { const unsigned char thisChar = source[i]; if (thisChar == ‘ ‘){ [output appendString:@"+"]; } else if (thisChar == ‘.‘ || thisChar == ‘-‘ || thisChar == ‘_‘ || thisChar == ‘~‘ || (thisChar >= ‘a‘ && thisChar <= ‘z‘) || (thisChar >= ‘A‘ && thisChar <= ‘Z‘) || (thisChar >= ‘0‘ && thisChar <= ‘9‘)) { [output appendFormat:@"%c", thisChar]; } else { [output appendFormat:@"%%%02X", thisChar]; } } return output; }
UIApplicationDidEnterBackgroundNotification 应用程序进入后台
UIApplicationWillEnterForegroundNotification 应用程序将要进入前台
UIApplicationDidFinishLaunchingNotification 应用程序完成启动
UIApplicationDidFinishLaunchingNotification 应用程序由挂起变的活跃
UIApplicationWillResignActiveNotification 应用程序挂起(有电话进来或者锁屏)
UIApplicationDidReceiveMemoryWarningNotification 应用程序收到内存警告
UIApplicationDidReceiveMemoryWarningNotification 应用程序终止(后台杀死、手机关机等)
UIApplicationSignificantTimeChangeNotification 当有重大时间改变(凌晨0点,设备时间被修改,时区改变等)
UIApplicationWillChangeStatusBarOrientationNotification 设备方向将要改变
UIApplicationDidChangeStatusBarOrientationNotification 设备方向改变
UIApplicationWillChangeStatusBarFrameNotification 设备状态栏frame将要改变
UIApplicationDidChangeStatusBarFrameNotification 设备状态栏frame改变
UIApplicationBackgroundRefreshStatusDidChangeNotification 应用程序在后台下载内容的状态发生变化
UIApplicationProtectedDataWillBecomeUnavailable 本地受保护的文件被锁定,无法访问
UIApplicationProtectedDataWillBecomeUnavailable 本地受保护的文件可用了
// 方法一 dispatch_async(dispatch_get_main_queue(), ^{ UIApplication *application = [UIApplication sharedApplication]; if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) { [application openURL:URL options:@{} completionHandler:nil]; } else { [application openURL:URL]; } }); // 方法二 [self performSelector:@selector(redirectToURL:) withObject:url afterDelay:0.1]; - (void) redirectToURL { UIApplication *application = [UIApplication sharedApplication]; if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) { [application openURL:URL options:@{} completionHandler:nil]; } else { [application openURL:URL]; } }
// modal方式 TestViewController *vc = [[TestViewController alloc] init]; vc.view.backgroundColor = [UIColor redColor]; vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:vc animated:YES completion:nil]; // push方式 TestViewController *vc = [[TestViewController alloc] init]; vc.view.backgroundColor = [UIColor redColor]; [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.80]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; [self.navigationController pushViewController:vc animated:YES]; [UIView commitAnimations];
- (void)viewWillLayoutSubviews { CGRect tabFrame = self.tabBar.frame; tabFrame.size.height = 100; tabFrame.origin.y = self.view.frame.size.height - 100; self.tabBar.frame = tabFrame; }
标签:nsdata 删除 lstat bar phone lin change 程序 复杂
原文地址:http://www.cnblogs.com/dianming/p/7211062.html