美文网首页
iOS 开发宏

iOS 开发宏

作者: 灬朴一生 | 来源:发表于2019-07-24 09:38 被阅读0次

持续更新Object-C

//
//  PublicDefine.h
//  TYZF_ElderlyService
//
//  Created by ll on 2015/10/13.
//  Copyright © 2015年 ll. All rights reserved.
//  综合开发宏

#ifndef PublicDefine_h
#define PublicDefine_h
#import <UIKit/UIKit.h>
// ---------------------------------------------------------------------------------------------

/** 字符串是否为空 */
#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))

/** 获取屏幕宽 */
#define kScreenWidth \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)

/** 获取屏幕高 */
#define kScreenHeight \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)

/** 获取屏幕尺寸 */
#define kScreenSize \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)

/** iPhone6 坐标适配 */
#define ScreenZoomScaleSix kScreenWidth/375.0f
#define ScreenSix(value) value *ScreenZoomScaleSix

#define ScreenZoomScaleSixHeight kScreenHeight/667.0f
#define ScreenSixHeight(value) value *ScreenZoomScaleSixHeight

/** 常用缩写 */
#define kApplication        [UIApplication sharedApplication]
#define kKeyWindow          [UIApplication sharedApplication].keyWindow
#define kAppDelegate        [UIApplication sharedApplication].delegate
#define kUserDefaults      [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

/** APP版本号 */
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

/** 手机序列号*/
#define kPhoneUUID [[UIDevice currentDevice] identifierForVendor]]

/** 系统版本号 */
#define kSystemVersion [[UIDevice currentDevice] systemVersion]

/** 获取当前语言 */
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

/** 判断是否为iPhone */
#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

/** 判断是否为iPad */
#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

/** 获取沙盒Document路径 */
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

/** 获取沙盒temp路径 */
#define kTempPath NSTemporaryDirectory()

/** 获取沙盒Cache路径 */
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

/** 判断是真机还是模拟器 */
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif

/** 开发的时候打印,但是发布的时候不打印的NSLog */
#ifdef DEBUG
#define NSLog(...) printf("\n\n %s_%d行 \n %s \n\n",__func__,__LINE__,[[NSString stringWithFormat:__VA_ARGS__] UTF8String])
#else
#define NSLog(...)
#endif

// 颜色
#define LColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define LColorRGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
#define LColorFromRGB(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 LRandomColor LColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

/** 由角度转换弧度 */
#define kDegreesToRadian(x)      (M_PI * (x) / 180.0)

/** 由弧度转换角度 */
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)

/** 获取一段时间间隔 */
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime  NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

/** 是否是iPhone X*/
#define IsIphoneX ((((kScreenWidth >= 375) && (kScreenHeight >= 812)  ) || \
((kScreenWidth >= 414) && (kScreenHeight >= 896)  )) ? 1 : 0)

// iPhone X以上 状态栏,导航栏,tabbar高度
/** 判断是否为iPhone*/
#define L_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/** 判断您是否为iPhone X 以上*/
#define L_iPhoneX kScreenWidth >=375.0f && kScreenHeight >=812.0f&& L_iphone
/*状态栏高度*/
#define kStatusBarHeight (CGFloat)(L_iPhoneX?(44.0):(20.0))
/*导航栏高度*/
#define kNavBarHeight (44)
/*状态栏和导航栏总高度*/
#define kNavBarAndStatusBarHeight (CGFloat)(L_iPhoneX?(88.0):(64.0))
/*TabBar高度*/
#define kTabBarHeight (CGFloat)(L_iPhoneX?(49.0 + 34.0):(49.0))
/*顶部安全区域远离高度*/
#define kTopBarSafeHeight (CGFloat)(L_iPhoneX?(44.0):(0))
/*底部安全区域远离高度*/
#define kBottomSafeHeight (CGFloat)(L_iPhoneX?(34.0):(0))
/*iPhoneX的状态栏高度差值*/
#define kTopBarDifHeight (CGFloat)(L_iPhoneX?(24.0):(0))
/*导航条和Tabbar总高度*/
#define kNavAndTabHeight (kNavBarAndStatusBarHeight + kTabBarHeight)

// ------------------------------------------------ 颜色 ---------------------------------------------------
/** 主体色 */
#define mainBodyColor LColorFromRGB(0xFFFFFF)  // 白色背景

/** 背景色 */
#define mainBackColor LColorFromRGB(0xE8E8E8) // 灰色背景

/** 黑色字体 */
#define textColorBlack LColorFromRGB(0x333333) // 黑色字体

/** 红色字体 */
#define textColorRed LColorFromRGB(0xE33939) // 红色字体

/** 深灰色字体 */
#define textColorDarkGrey LColorFromRGB(0x999999) // 深灰色字体

/** 分割线色字体 */
#define dividingLineColor LColorFromRGB(0xEEEEEE) // 深灰色字体

// ------------------------------------------------ 字体 ---------------------------------------------------
/** 字体宏 */
#define default_Font(font) [UIFont systemFontOfSize:ScreenSix(font)];

// ------------------------------------------------ 图片 ---------------------------------------------------
/** 提交按钮背景图 */
#define submitButtonImage @"" // 背景图

/** 控件默认背景图 */
#define controlsDefaultImage @""

// ---------------------------------------------------------------------------------------------
/** QQ____APPKey */
static NSString *const MainQQAppKey = @"";
/** QQ____APPID */
static NSString *const MainQQAppID = @"";

/** 微信____APPKey */
static NSString *const MainWXAppKey = @"";
/** 微信____APPID */
static NSString *const MainWXAppID = @"";

/** 支付宝_______APPID*/
static NSString *const MainAliAppID = @"";

// ---------------------------------------------------------------------------------------------
/** 搜索缓存名称 */
static NSString *const SearchSaveName = @"Search";

/** 全局变量类*/
#define GlobalVarSingle [GlobalVar sharedGlobalVar]
#endif /* PublicDefine_h */

相关文章

网友评论

      本文标题:iOS 开发宏

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