美文网首页ios开发整理
iOS 开发常用宏定义

iOS 开发常用宏定义

作者: 今晚月色 | 来源:发表于2018-05-19 18:27 被阅读42次
#define IS_iPhoneX ([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 812)
#define IPHONEX_MARGIN_TOP (88)
#define IPHONEX_MARGIN_BOTTOM (34)

// App Frame
#define Application_Frame       [[UIScreen mainScreen] applicationFrame]

// App Frame Height&Width
#define App_Frame_Height        [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width         [[UIScreen mainScreen] applicationFrame].size.width

// MainScreen Height&Width
#define Screen_Height      [[UIScreen mainScreen] bounds].size.height
#define Screen_Width       [[UIScreen mainScreen] bounds].size.width

/**
 *  IphoneX适配
 */
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
/**
 *  状态栏高度
 */
#define STATUS_BAR_HEIGHT (iPhoneX ? 44.f : 20.f)
/**
 *  导航栏高度
 */
#define NAVIGATION_BAR_HEIGHT (iPhoneX ? 88.f : 64.f)
/**
 *  tabBar高度
 */
#define TAB_BAR_HEIGHT (iPhoneX ? (49.f+34.f) : 49.f)
/**
 *  home indicator
 */
#define HOME_INDICATOR_HEIGHT (iPhoneX ? 34.f : 0.f)

#define TAB_HEIGHT (iPhoneX ? 208.f : 153.f)

// View 坐标(x,y)和宽高(width,height)
#define X(v)                    (v).frame.origin.x
#define Y(v)                    (v).frame.origin.y

#define WIDTH(v)                (v).frame.size.width
#define HEIGHT(v)               (v).frame.size.height

#define MinX(v)                 CGRectGetMinX((v).frame)
#define MinY(v)                 CGRectGetMinY((v).frame)

#define MidX(v)                 CGRectGetMidX((v).frame)
#define MidY(v)                 CGRectGetMidY((v).frame)

#define MaxX(v)                 CGRectGetMaxX((v).frame)
#define MaxY(v)                 CGRectGetMaxY((v).frame)

// 加载图片
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

// 颜色(RGB)
#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)]
// 随机颜色
#define RANDOM_UICOLOR     [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]

///字体
#define G_FONT_TEXT(a) [UIFont systemFontOfSize:WD_ScaleFont(a)]

/**宽度比例*/
#define WD_ScaleWidth(__VA_ARGS__)  ([UIScreen mainScreen].bounds.size.width/375.f)*(__VA_ARGS__)

/**高度比例*/
#define WD_ScaleHeight(__VA_ARGS__)  ([UIScreen mainScreen].bounds.size.height/667.f)*(__VA_ARGS__)

/**字体比例*/
#define WD_ScaleFont(__VA_ARGS__)  ([UIScreen mainScreen].bounds.size.width/375.f)*(__VA_ARGS__)

// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

// alert
#define Alert(_S_, ...)     [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil] show]

// 检查字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )

// 检查数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)

// 检查字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)

// 检查是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

// APP对象 (单例对象)
#define kApplication [UIApplication sharedApplication]
// 主窗口 (keyWindow)
#define kKeyWindow [UIApplication sharedApplication].keyWindow
// APP对象的delegate
#define kAppDelegate [UIApplication sharedApplication].delegate
// NSUserDefaults实例化
#define kUserDefaults [NSUserDefaults standardUserDefaults]
// 通知中心 (单例对象)
#define kNotificationCenter [NSNotificationCenter defaultCenter]

// 弱引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
// 强引用
#define kStrongSelf(type) __strong typeof(type) type = weak##type;

相关文章

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • iOS开发常用的工具类和宏定义

    iOS开发常用的工具类和宏定义 开发总结的工具类和宏 https://github.com/xiaoChen66...

  • iOS开发中常用的宏

    以下为iOS开发中常用宏: 引用:ios开发常用的宏,大家一起来收集 参考:ios开发常用的宏,大家一起来收集~

  • iOS 开发小经验

    iOS 开发中你是否遇到这些经验问题(一)iOS 开发中你是否遇到这些经验问题(二)iOS 日常工作之常用宏定义大全

  • iOS开发中常用的宏定义

    iOS开发中常用的宏定义 尺寸宏 打印宏 替换NSLog来使用,debug模式下可以打印很多方法名,行信息。 #...

  • iOS 开发常用宏定义

  • iOS开发常用宏定义

    做开发不久,经常会上网找一些资料,简书上的内容是看着比较顺眼的了;特此也想把平时工作中遇到的问题总结记录下来,希望...

  • iOS开发常用宏定义

    iOS 日常工作之常用宏定义大全iOS-OC中常见的一些宏YYCategories 目录 1、长、宽、高2、判断设...

  • iOS 开发常用宏定义

  • iOS开发常用宏定义

    判断设备类型iPad/iPhone#define IS_IPAD(UI_USER_INTERFACE_IDIOM(...

网友评论

本文标题:iOS 开发常用宏定义

本文链接:https://www.haomeiwen.com/subject/vpjadftx.html