ios开发中,比较实用的全局宏定义分享
2013-07-28 23:07
716 查看
分享几个我日常开发中常用的宏定义头文件:有日志、颜色、距离、坐标等基本宏:
// // Commons.h // // Created by Block Cheng on 12-6-7. // Copyright (c) 2012年 Block Cheng. All rights reserved. // #define LOGOPEN 1 #define VC_LOGOPEN 1 #define DB_BLOCK_LOG #define NET_BLOCK_LOG 1 #pragma mark ---log flag #define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height) #define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y) #if LOGOPEN #define DDDLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); #else #define DDDLog(FORMAT, ...) #endif //viewController log #ifdef VC_LOGOPEN #define LogVC DDDLog #else #define LogVC #endif //dbbase log #ifdef DB_BLOCK_LOG #define LogDB DDDLog #else #define LogDB #endif //networking log #if NET_BLOCK_LOG #define LogNET DDDLog #else #define LogNET #endif //view log #ifdef VIEW_BLOCK_LOG #define LogVIEW DDDLog #else #define LogVIEW #endif #pragma mark --time setup #if TARGET_IPHONE_SIMULATOR #import <objc/objc-runtime.h> #else #import <objc/runtime.h> #endif #ifdef _DEBUG #define DNSLog(...); NSLog(__VA_ARGS__); #define DNSLogMethod NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd)); #define DNSLogPoint(p) NSLog(@"%f,%f", p.x, p.y); #define DNSLogSize(p) NSLog(@"%f,%f", p.width, p.height); #define DNSLogRect(p) NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height); CFAbsoluteTime startTime; #define D_START startTime=CFAbsoluteTimeGetCurrent(); #define D_END DNSLog(@"[%s] %@ %f seconds", class_getName([self class]), NSStringFromSelector(_cmd), CFAbsoluteTimeGetCurrent() - startTime ); #else #define DNSLog(...); // NSLog(__VA_ARGS__); #define DNSLogMethod // NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd) ); #define DNSLogPoint(p) // NSLog(@"%f,%f", p.x, p.y); #define DNSLogSize(p) // NSLog(@"%f,%f", p.width, p.height); #define DNSLogRect(p) // NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height); #define D_START // CFAbsoluteTime startTime=CFAbsoluteTimeGetCurrent(); #define D_END // DNSLog(@"New %f seconds", CFAbsoluteTimeGetCurrent() - startTime ); #endif #define SAFE_FREE(p) { if(p) { free(p); (p)=NULL; } } #pragma mark ---- AppDelegate //AppDelegate #define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication] delegate] //UIApplication #define APPD [UIApplication sharedApplication] #define rootNavVC (UINavigationController*)[[[[UIApplication sharedApplication] delegate] window] rootViewController] #define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) #define isiPhone5 ([[UIScreen mainScreen]bounds].size.height == 568) #pragma mark ---- String functions #define EMPTY_STRING @"" #define STR(key) NSLocalizedString(key, nil) #pragma mark ---- UIImage UIImageView functions #define IMG(name) [UIImage imageNamed:name] #define IMGF(name) [UIImage imageNamedFixed:name] #pragma mark ---- File functions #define PATH_OF_APP_HOME NSHomeDirectory() #define PATH_OF_TEMP NSTemporaryDirectory() #define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] #pragma mark ---- color functions #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1] #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)] #pragma mark ----Size ,X,Y, View ,Frame //get the size of the Screen #define SCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height #define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width #define HEIGHT_SCALE ([[UIScreen mainScreen]bounds].size.height/480.0) //get the size of the Application #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width #define APP_SCALE_H ([[UIScreen mainScreen]applicationFrame].size.height/480.0) #define APP_SCALE_W ([[UIScreen mainScreen]applicationFrame].size.width/320.0) //get the left top origin's x,y of a view #define VIEW_TX(view) (view.frame.origin.x) #define VIEW_TY(view) (view.frame.origin.y) //get the width size of the view:width,height #define VIEW_W(view) (view.frame.size.width) #define VIEW_H(view) (view.frame.size.height) //get the right bottom origin's x,y of a view #define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width) #define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height ) //get the x,y of the frame #define FRAME_TX(frame) (frame.origin.x) #define FRAME_TY(frame) (frame.origin.y) //get the size of the frame #define FRAME_W(frame) (frame.size.width) #define FRAME_H(frame) (frame.size.height) #define DistanceFloat(PointA,PointB) sqrtf((PointA.x - PointB.x) * (PointA.x - PointB.x) + (PointA.y - PointB.y) * (PointA.y - PointB.y))
相关文章推荐
- ios开发中,比较实用的全局宏定义分享
- iOS开发笔记--一些实用的宏定义
- 一些iOS开发中一些实用的Demo分享
- iOS开发常见的宏定义(实用)
- 分享iOS开发常用(三方类库,工具,高仿APP,实用网站,技术干货)
- iOS开发常用的全局宏定义
- iOS开发笔记--一些实用的宏定义
- 分享一些iOS开发实用的小技巧
- iOS开发零碎知识点---(有一些还是比较实用的)。
- iOS 给大家推荐一些项目中比较实用的小 demo
- iOS-为方便项目开发在pch添加一些常用宏定义
- ios开发学习--按钮(Button)效果源码分享--系列教程3
- iOS开发之NSString的几条实用技巧
- 一个iOS开发者业余开发自己APP的经验分享
- iOS开发常见技术链接分享
- iOS开发经验分享:如何在业余时间开发出百万用户的 App?
- IOS开发之——友盟社会化分享UMSocial_SDK的使用
- IOS,UITextField比较全的实用的属性功能
- iOS开发-在pch文件中添加全局宏可以打印控制器地址方便调试
- iOS开发——全局响应MotionEvent