ios android 宏,iOS常用宏(不断更新)

#define后面一般不加;

宏里面用#argc,是要取argc的值

按比例拉伸??在iPhone6尺寸应该是什么样的高度!

#define DIMENSION_SELF_ADAPT(width, height)\

(width > 0 ? height * kScreenWidth / width : 0)

#define DIMENSION_SELF_ADAPT_375(height) DIMENSION_SELF_ADAPT(375, height)

宏定义

#ifndef MGMacro_h

#define MGMacro_h

……

#endif /* MGMacro_h */

颜色宏

/************ 随机颜色 ************/

#define kRandomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0]

// rgb颜色转换(十六进制)

#define kColorWithHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define kColorWithRGB(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0]

#define kColorWithRGBA(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

尺寸宏

/************ 屏幕尺寸 ************/

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define STATUS_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height

#define StatusBar_HEIGHT 20

#define NavigationBar_HEIGHT 44

#define NavigationBarIcon 20

#define TabBar_HEIGHT 49

#define TabBarIcon 30

// 获取view的frame属性

#define GetViewWidth(view) view.frame.size.width

#define GetViewHeight(view) view.frame.size.height

#define GetViewX(view) view.frame.origin.x

#define GetViewY(view) view.frame.origin.y

工具宏

/************ 角度转弧度 ************/

#define kDegrees2Radian(x) (M_PI * (x) / 180.0)

//弧度转角度

#define kRadian2Degrees(radian) (radian * 180.0) / (M_PI)

// 去掉首尾空格

#define TRIM(tempStr) [tempStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]

// 获取图片资源

#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

// 读取本地图片

#define kLoadImage(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

打印宏

/************ 自定义NSLog ************/

#ifdef DEBUG

#define MGLog(...) NSLog(__VA_ARGS__)

#else

#define MGLog(...)

#endif

// 打印方法名

#define MGLogFunc MGLog(@"%s",__FUNCTION__);

设备宏

/************ APP版本号 ************/

#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

// APP名称

#define kAppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]

// 获取当前语言

#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

// 判断是否为iPhone

#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

// 判断是否为iPad

#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

// 系统版本号

#define kSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]

// 判断是否为iOS8

#define iOS8 ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)

// 根据尺寸判断 是否为4inch

#define is4Inch ([UIScreen mainScreen].bounds.size.height == 568)

文件宏

/************ 获取沙盒Document路径 ************/

#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

// 获取沙盒temp路径

#define kTempPath NSTemporaryDirectory()

// 获取沙盒Cache路径

#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

系统宏

/************ 系统application ************/

#define kApplication [UIApplication sharedApplication]

#define kKeyWindow [UIApplication sharedApplication].keyWindow

#define kAppDelegate [UIApplication sharedApplication].delegate

#define kUserDefaults [NSUserDefaults standardUserDefaults]

#define kNotificationCenter [NSNotificationCenter defaultCenter]

判断宏

/************ 判断 ARC 和 MRC ************/

#if __has_feature(objc_arc)

// ARC

#else

// MRC

#endif

/************ 判断 真机 和 模拟器 ************/

#if TARGET_OS_IPHONE

// iPhone Device

#endif

#if TARGET_IPHONE_SIMULATOR

// iPhone Simulator

#endif

弱引用/强引用

#define kWeakSelf(type) __weak typeof(type) weak##type = type;

#define kStrongSelf(type) __strong typeof(type) type = weak##type;

适配屏幕尺寸宽高比

#define KWidth(width) (IS_SCREEN_4_INCH ? (width * (CGFloat)320 / 375):(IS_SCREEN_47_INCH ? (width):(width *(CGFloat)414 / 375)))

#define KHeight(height) (IS_SCREEN_4_INCH ? (height * (CGFloat)568 / 667):(IS_SCREEN_47_INCH ? (height):(height *(CGFloat)736 / 667)))

IS_SCREEN_4_INCH

判断系统版本代码

// 判断系统版本

#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

+ (UIDevice *)currentDevice;

@property(nonatomic,readonly,retain) NSString *name; // e.g. "My iPhone"

@property(nonatomic,readonly,retain) NSString *model; // e.g. @"iPhone", @"iPod touch"

@property(nonatomic,readonly,retain) NSString *localizedModel; // localized version of model

@property(nonatomic,readonly,retain) NSString *systemName; // e.g. @"iOS"

@property(nonatomic,readonly,retain) NSString *systemVersion; // e.g. @"4.0"

@property(nonatomic,readonly) UIDeviceOrientation orientation; // return current device orientation. this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.

@property(nonatomic,readonly,retain) NSUUID *identifierForVendor NS_AVAILABLE_IOS(6_0); // a UUID that may be used to uniquely identify the device, same across apps from a single vendor.

待修改!!!

网络宏

#define APIURL @"http://xxxxx/"

#define APILogin [APIURL stringByAppendingString:@"Login"]

// 账号相关信息

#define kAppKey @"3637170628"

#define kAppSecret @"b4990ef2e737298552a1c8388fca78c3"

#define kRedirectURI @"https://api.weibo.com/oauth2/default.html"

其他宏

// 方正黑体简体字体定义

#define FONT(size) [UIFont fontWithName:@"FZHTJW--GB1-0" size:size]

//获取一段时间间隔

#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

#define kEndTime NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

颜色相关知识

24-bit位颜色,每一位占8道,3个颜色通道

白色 #ffffff 最不纯净的颜色

黑色 #000000 是最纯净的颜色

红色 #ff0000

黄色 #ffff00

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值