1、JSON解析
- (NSDictionary *)serializedData:(NSData *)data { NSError *JSONSerializationError; NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&JSONSerializationError]; if(JSONSerializationError) { [NSException raise:@"JSON Serialization Error" format:@"Failed to parse weather data"]; } return JSON; }
2、背景模糊,需要UIImage+ImageEffects
- (void)setBlurredOverlayImage { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ { // Take a screen shot of this controller's view UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Blur the screen shot UIImage *blurred = [image applyBlurWithRadius:20 tintColor:[UIColor colorWithWhite:0.15 alpha:0.5] saturationDeltaFactor:1.5 maskImage:nil]; dispatch_async(dispatch_get_main_queue(), ^ { // Set the blurred overlay view's image with the blurred screenshot self.blurredOverlayView.image = blurred; }); }); }
3、计算pageControl的页码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // Update the current page for the page control float fractionalPage = self.pagingScrollView.contentOffset.x / self.pagingScrollView.frame.size.width; self.pageControl.currentPage = lround(fractionalPage); }
4、图像缩放
+ (UIImage *)scale:(UIImage *)sourceImg toSize:(CGSize)size { UIGraphicsBeginImageContext(size); [sourceImg drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; } + (CGSize)scaleSize:(CGSize)sourceSize { float width = sourceSize.width; float height = sourceSize.height; if (width >= height) return CGSizeMake(800, 800 * height / width); else return CGSizeMake(800 * width / height, 800); }
5、ASIHTTPRequest取消请求
+ (void)CancelRequest:(ASIHTTPRequest *)request { if (request != nil) { [request cancel]; [request clearDelegatesAndCancel]; } }
6、debug log switch
#ifdef DEBUG # define NSLog(...) NSLog(__VA_ARGS__) #else # define NSLog(...) {} #endif
7、Disk cache
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache];
8、AFNetworking
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; [[AFNetworkReachabilityManager sharedManager] startMonitoring]; [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { NSString* title = @"网络未连接"; switch (status) { case AFNetworkReachabilityStatusNotReachable: title = @"网络未连接"; break; case AFNetworkReachabilityStatusReachableViaWiFi: title = @"当前wifi已连接"; break; case AFNetworkReachabilityStatusReachableViaWWAN: title = @"当前2g/3g已连接"; break; default: break; } [RCGlobalConfig HUDShowMessage:title addedToView:[UIApplication sharedApplication].keyWindow]; }];
9、MBProgressHUD
+ (MBProgressHUD *)HUDShowMessage:(NSString *)msg addedToView:(UIView *)view { static MBProgressHUD *hud = nil; if (!hud) hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.mode = MBProgressHUDModeText; hud.labelText = msg; hud.hidden = NO; hud.alpha = 1.0f; [hud hide:YES afterDelay:1.0f]; return hud; }
10、UIBarButtonItem
+ (UIBarButtonItem *)createBarButtonItemWithTitle:(NSString *)buttonTitle Target:(id)target action:(SEL)action { UIBarButtonItem *item = nil; item = [[UIBarButtonItem alloc] initWithTitle:buttonTitle style:UIBarButtonItemStylePlain target:target action:action]; return item; } + (UIBarButtonItem *)createMenuBarButtonItemWithTarget:(id)target action:(SEL)action { return [[UIBarButtonItem alloc] initWithImage:[UIImage nimbusImageNamed:@"icon_menu.png"] style:UIBarButtonItemStylePlain target:target action:action]; } + (UIBarButtonItem *)createRefreshBarButtonItemWithTarget:(id)target action:(SEL)action { UIBarButtonItem *item = nil; item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:target action:action]; return item; }
11、获取UIView对应的UIViewController
#import <UIKit/UIKit.h> @interface UIView (findViewController) - (UIViewController *)viewController; @end #import "UIView+findViewController.h" @implementation UIView (findViewController) - (UIViewController *)viewController { // Traverse responder chain. Return first found view controller, which will be the view's view controller. UIResponder *responder = self; while ((responder = [responder nextResponder])) if ([responder isKindOfClass:[UIViewController class]]) return (UIViewController *)responder; // If the view controller isn't found, return nil. return nil; } @end
12、获取图片,需要nimbus
#import <UIKit/UIKit.h> @interface UIImage (nimbusImageNamed) + (UIImage *)nimbusImageNamed:(NSString *)imageName; @end #import "UIImage+nimbusImageNamed.h" @implementation UIImage (nimbusImageNamed) + (UIImage *)nimbusImageNamed:(NSString *)imageName { NSString *imagePath = NIPathForBundleResource(nil, imageName); UIImage *image = [[Nimbus imageMemoryCache] objectWithName:imagePath]; if (nil == image) { image = [UIImage imageWithContentsOfFile:imagePath]; // store it in memory [[Nimbus imageMemoryCache] storeObject:image withName:imagePath]; } return image; } @end
13、保存图片
if(photoView.image) UIImageWriteToSavedPhotosAlbum(photoView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
14、获取文件内容
+ (NSString *)contentForFile:(NSString *)file ofType:(NSString *)type { NSString *filePath=[[NSBundle mainBundle] pathForResource:file ofType:type]; NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; return content; }
15、获取AppDelegate
+ (SFAppDelegate *)applicationDelegate { return (SFAppDelegate *)[[UIApplication sharedApplication] delegate]; }
16、计算字符高度
+ (float)heightOfString:(NSString *)string withWidth:(float)width font:(UIFont *)font { if ([NSNull null] == (id)string) string = @"暂时没有数据"; CGSize constraintSize = CGSizeMake(width, MAXFLOAT); CGSize labelSize = [string sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; return labelSize.height; }
17、设置cookie
NSHTTPCookie *uidCookie = [NSHTTPCookie cookieWithProperties: [NSDictionary dictionaryWithObjectsAndKeys: @"sfuid", NSHTTPCookieName, @"", NSHTTPCookieValue, @".segmentfault.com", NSHTTPCookieDomain, @"segmentfault.com", NSHTTPCookieOriginURL, @"/", NSHTTPCookiePath, @"0", NSHTTPCookieVersion, nil]]; [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:uidCookie];
18、定义枚举
typedef NS_OPTIONS(NSUInteger, MLDays) { ML_DAYS_ONCE = 0, ML_DAYS_MON = 1, ML_DAYS_TUE = 1 << 1, ML_DAYS_WED = 1 << 2, ML_DAYS_THU = 1 << 3, ML_DAYS_FRI = 1 << 4, ML_DAYS_SAT = 1 << 5, ML_DAYS_SUN = 1 << 6, ML_DAYS_ALL = 0x1111111 };
19、判断是否为空
static inline BOOL isEmpty(id thing) { return thing == nil || thing == [NSNull null] || ([thing respondsToSelector:@selector(length)] && [(NSData *)thing length] == 0) || ([thing respondsToSelector:@selector(count)] && [(NSArray *)thing count] == 0); }
相关推荐
持续更新中…… 目录 [Apple Watch Demo](#Apple Watch Demo) 内容 Swift教程 iOS教程 - 动画教程写的很赞 - 很赞iPHone适配相关的教程 - 以公司或团体名义在苹果AppStore上架APP - 666的分许了网易的导航实现方式 ...
* CATransition 常用设置及属性注解如下: */ CATransition *animation = [CATransition animation]; /** delegate * * 动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两...
下面总结了iOS开发过程中的一些常用宏,会持续的往里面添加。 Objective-C //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO ...
iOS开发常用三方库、插件、知名博客等等,持续更新。。。 使用方法:根据目录关键字搜索(Commond + F),记得包含@,以保证搜索目录关键字的唯一性。 问题反馈:请广大网友只按照目录结构(即使目录结构有问题)添加...
该文档会持续更新,同时也欢迎更多具有丰富经验的iOS开发者将自己的常用的一些工具,学习资料,学习心得等分享上来,我将定期筛选合并,文档尚有一些不完善之处,也请不吝指出,感谢您对iOS所做的贡献,让我们一起把国内的...
一、简介 IOS 动画主要是指Core Animation...常用属性 duration : 动画的持续时间 beginTime : 动画的开始时间 repeatCount : 动画的重复次数 autoreverses : 执行的动画按照原动画返回执行 timingFunction : 控制动画
- iOS开发中最常用的脚本语言,OS X预装了Ruby。 - ruby环境管理工具。 - facebook出品的命令行工具,替代苹果官方的XcodeBuild工具,非Xcode环境下的构建利器,往往是持续集成的首选。 - 苹果风格文档生成器。 ...
该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发者将自己的常用的一些工具, 学习资料, 学习心得等分享上来, 我将定期筛选合并, 文档尚有一些不完善之处, 也请不吝指出, 感谢您对 iOS 所做的贡献, 让我们...
1、项目基础框架和分类 2、BaseNavigationController、BaseViewController、BaseTableViewController、BaseView等基类 3、常用一些第三方框架集成 4、常用的一些扩展 5、一些demo实例
该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发者将自己的常用的一些工具, 学习资料, 学习心得等分享上来, 我将定期筛选合并, 文档尚有一些不完善之处, 也请不吝指出, 感谢您对 iOS 所做的贡献, 让我们...
该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发者将自己的常用的一些工具, 学习资料, 学习心得等分享上来, 我将定期筛选合并, 文档尚有一些不完善之处, 也请不吝指出, 感谢您对 iOS 所做的贡献, 让我们...
持续更新中... 软件架构 软件架构说明 安装教程 下载文件到本地, cd 到根目录文件夹下, 命令行执行: npm install install 完毕后, react-native run-ios 或者 react-native run-android 运行项目 使用说明 本项目暂...
这么看下去还有大量的内容需要持续补充,但是今天我们从最基础的C语言开始,C语言部分我将分成几个章节去说,今天我们简单看一下C的一些基础知识,更高级的内容我将放到后面的文章中。 今天基础知识分为以下几点内容...
该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发者将自己的常用的一些工具, 学习资料, 学习心得等分享上来, 我将定期筛选合并, 文档尚有一些不完善之处, 也请不吝指出, 感谢您对 iOS 所做的贡献, 让我们...
项目使用皆是当前主流前后端技术栈(持续更新...),无过度自定义封装,易理解学习和二次扩展; Spring Boot 3 、SpringCloud & Alibaba 2022 一站式微服务开箱即用的解决方案; Spring Authorization Server 、 JWT ...
项目使用皆是当前主流前后端技术栈(持续更新...),无过度自定义封装,易理解学习和二次扩展; Spring Boot 3 、SpringCloud & Alibaba 2022 一站式微服务开箱即用的解决方案; Spring Authorization Server 、 JWT ...
collection控件用来实现界面的各种自定义布局,最常用其作为横向、竖向的...本文主要介绍自定义collection的设计与实现,后续持续更新多tab的tabview控件。 我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相