赞
踩
新建一个.h文件,把自动生成的代码删掉,把下面的代码复制进去,导入头文件到pch,就可以用了
- //
- // JJMacros.h
- // test2.7
- //
- // Created by muzhong on 2017/3/14.
- // Copyright © 2017年 muzhong. All rights reserved.
- //
-
- #import <mach/mach_time.h> // for mach_absolute_time() and friends
-
- #import <CoreGraphics/CGBase.h>
-
- #pragma mark -
- #pragma mark Syntactic sugar
-
- #define NOT_ANIMATED NO
- #define ANIMATED YES
-
- #pragma mark -
- #pragma mark UIColor
-
- // example usage: UIColorFromHex(0x9daa76)
- #define UIColorFromHexWithAlpha(hexValue,a) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:a]
- #define UIColorFromHex(hexValue) UIColorFromHexWithAlpha(hexValue,1.0)
- #define UIColorFromRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
- #define UIColorFromRGB(r,g,b) UIColorFromRGBA(r,g,b,1.0)
- #define kMainColor [UIColor colorWithRed:(10)/255.0 green:(166)/255.0 blue:(246)/255.0 alpha:1.0]
- #define kBgColor [UIColor colorWithRed:(239)/255.0 green:(239)/255.0 blue:(239)/255.0 alpha:1.0]
-
-
- #pragma mark -
- #pragma mark Logging
-
- #define LOG(fmt, ...) NSLog(@"%s: " fmt, __PRETTY_FUNCTION__, ## __VA_ARGS__)
-
- #ifdef DEBUG
- #define INFO(fmt, ...) LOG(fmt, ## __VA_ARGS__)
- #else
- // do nothing
- #define INFO(fmt, ...)
- #endif
-
- #define ERROR(fmt, ...) LOG(fmt, ## __VA_ARGS__)
- #define TRACE(fmt, ...) LOG(fmt, ## __VA_ARGS__)
-
- #define METHOD_NOT_IMPLEMENTED() NSAssert(NO, @"You must override %@ in a subclass", NSStringFromSelector(_cmd))
-
- #pragma mark -
- #pragma mark NSNumber
-
- #define NUM_INT(int) [NSNumber numberWithInt:int]
- #define NUM_FLOAT(float) [NSNumber numberWithFloat:float]
- #define NUM_BOOL(bool) [NSNumber numberWithBool:bool]
-
- #pragma mark -
- #pragma mark Frame Geometry
-
- #define CENTER_VERTICALLY(parent,child) floor((parent.frame.size.height - child.frame.size.height) / 2)
- #define CENTER_HORIZONTALLY(parent,child) floor((parent.frame.size.width - child.frame.size.width) / 2)
-
- // example: [[UIView alloc] initWithFrame:(CGRect){CENTER_IN_PARENT(parentView,500,500),CGSizeMake(500,500)}];
- #define CENTER_IN_PARENT(parent,childWidth,childHeight) CGPointMake(floor((parent.frame.size.width - childWidth) / 2),floor((parent.frame.size.height - childHeight) / 2))
- #define CENTER_IN_PARENT_X(parent,childWidth) floor((parent.frame.size.width - childWidth) / 2)
- #define CENTER_IN_PARENT_Y(parent,childHeight) floor((parent.frame.size.height - childHeight) / 2)
-
- #define WIDTH(view) view.frame.size.width
- #define HEIGHT(view) view.frame.size.height
- #define X(view) view.frame.origin.x
- #define Y(view) view.frame.origin.y
- #define LEFT(view) view.frame.origin.x
- #define TOP(view) view.frame.origin.y
- #define BOTTOM(view) (view.frame.origin.y + view.frame.size.height)
- #define RIGHT(view) (view.frame.origin.x + view.frame.size.width)
-
-
- #pragma mark -
- #pragma mark Screen size
-
- #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
- #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
- //以6为标准
- #define adoptValue(a) (a*(SCREEN_WIDTH/375.0))
- //导航栏高度
- #define kNavBarHeight 64
-
-
- #pragma mark -
- #pragma mark other
-
- // 弱引用相关
- #ifndef weakify
- #if DEBUG
- #if __has_feature(objc_arc)
- #define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
- #else
- #define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
- #endif
- #else
- #if __has_feature(objc_arc)
- #define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
- #else
- #define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
- #endif
- #endif
- #endif
-
- #ifndef strongify
- #if DEBUG
- #if __has_feature(objc_arc)
- #define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
- #else
- #define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
- #endif
- #else
- #if __has_feature(objc_arc)
- #define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
- #else
- #define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
- #endif
- #endif
- #endif
-
-
- //当前window
- #define kCurrentWindow [[UIApplication sharedApplication].windows firstObject]
-
- //非空的字符串 避免输出null
- #define kUnNilStr(str) ((str && ![str isEqual:[NSNull null]])?str:@"")
-
- //app名称
- #define kAppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
-
- //app版本
- #define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
-
- #pragma mark -
- #pragma mark Device type.
- // Corresponds to "Targeted device family" in project settings
- // Universal apps will return true for whichever device they're on.
- // iPhone apps will return true for iPhone even if run on iPad.
-
- #define TARGETED_DEVICE_IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
- #define TARGETED_DEVICE_IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
- #define TARGETED_DEVICE_IS_IPHONE_568 TARGETED_DEVICE_IS_IPHONE && SCREEN_HEIGHT == 568
-
- #pragma mark -
- #pragma mark Transforms
-
- #define DEGREES_TO_RADIANS(degrees) degrees * M_PI / 180
-
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。