iOS_常用宏定义

NLog处理

  • 设置Build Setings -> Preprocessor Mecros -> Debug DEBUG=1 Build
    Build Setings -> Preprocessor Mecros -> Release
#pragma mark -  NSLog在release下不输出
#ifdef DEBUG
#define NSLog(formater,...) NSLog((@"\n[文件名:%s] " "函数名:%s\n" "代码行数: %d " formater),[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__)
#else
#define NSLog(...) /* */
#endif
//nslog 输入参数不全时 用MyLog
#define MyLog(format, ...) printf("文件名: <%s 代码行数:(%d) >\n函数名: %s \n%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )

weakself设置

#define AAWeakSelf(type) autoreleasepool{} __weak typeof(type) weak##type = type;
#define AAStrongSelf(type) autoreleasepool{} __strong typeof(type) type = weak##type;

#define kWeakSelf(type) @AAWeakSelf(type);
#define kStrongSelf(type) @AAStrongSelf(type);

常用宽高

#pragma mark -  常用宽高
#define kWidth ([UIScreen mainScreen].bounds.size.width)
#define kHeight ([UIScreen mainScreen].bounds.size.height)

#define kStatusBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 44.0 : 20.0)
#define kNavBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 88.0 : 64.0)
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 83.0 : 49.0)
#define kTabBarBottom ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 34.0 : 0)

文字字体

#pragma mark -  文字字体
//超细字体
#define kFontSys_UltraLight(s) [UIFont systemFontOfSize:s weight:UIFontWeightUltraLight]
//纤细字体
#define kFontSys_Thin(s) [UIFont systemFontOfSize:s weight:UIFontWeightThin]
//亮字体
#define kFontSys_Light(s) [UIFont systemFontOfSize:s weight:UIFontWeightLight]
//常规字体
#define kFontSys_Regular(s) [UIFont systemFontOfSize:s weight:UIFontWeightRegular]
//介于Regular和Semibold之间
#define kFontSys_Medium(s) [UIFont systemFontOfSize:s weight:UIFontWeightMedium]
//半粗字体
#define kFontSys_Semibold(s) [UIFont systemFontOfSize:s weight:UIFontWeightSemibold]
//加粗字体
#define kFontSys_Bold(s) [UIFont systemFontOfSize:s weight:UIFontWeightBold]
//介于Bold和Black之间
#define kFontSys_Heavy(s) [UIFont systemFontOfSize:s weight:UIFontWeightHeavy]
//最粗字体(理解)
#define kFontSys_Black(s) [UIFont systemFontOfSize:s weight:UIFontWeightBlack]
//自定义字体大小
#define kFontName(name,s) [UIFont fontWithName:name size:s]
//设定字体大小和宽度
#define kFontWeight(w,s) [UIFont monospacedDigitSystemFontOfSize:s weight:w]

取色值相关的方法

#pragma mark -  取色值相关的方法
#define kRamdomColor [UIColor colorWithRed:(arc4random() % 256)/255.0 green:(arc4random() % 256)/255.0 blue:(arc4random() % 256)/255.0 alpha:1]

#define kRGB(r,g,b)          [UIColor colorWithRed:(r)/255.f \
green:(g)/255.f \
blue:(b)/255.f \
alpha:1.f]

#define kRGBW(w)          [UIColor colorWithRed:(w)/255.f \
green:(w)/255.f \
blue:(w)/255.f \
alpha:1.f]

#define kRGBA(r,g,b,a)       [UIColor colorWithRed:(r)/255.f \
green:(g)/255.f \
blue:(b)/255.f \
alpha:(a)]

#define kRGB_OF(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 kRGBA_OF(rgbValue)   [UIColor colorWithRed:((float)(((rgbValue) & 0xFF000000) >> 24))/255.0 \
green:((float)(((rgbValue) & 0x00FF0000) >> 16))/255.0 \
blue:((float)(rgbValue & 0x0000FF00) >> 8)/255.0 \
alpha:((float)(rgbValue & 0x000000FF))/255.0]

#define kRGBAOF(v, a)        [UIColor colorWithRed:((float)(((v) & 0xFF0000) >> 16))/255.0 \
green:((float)(((v) & 0x00FF00) >> 8))/255.0 \
blue:((float)(v & 0x0000FF))/255.0 \
alpha:a]

通知消息

//获取通知中心
#define kNotificationCenter [NSNotificationCenter defaultCenter]
//快速发通知
#define kPost_Notify(_notificationName, _obj, _userInfoDictionary) [[NSNotificationCenter defaultCenter] postNotificationName: _notificationName object: _obj userInfo: _userInfoDictionary];
//添加观察者
#define kAdd_Observer(_observer, _notificationName, _observerSelector, _obj) [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(_observerSelector) name:_notificationName object: _obj];
//移除观察者
#define kRemove_Observer(_observer) [[NSNotificationCenter defaultCenter] removeObserver: _observer];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值