当有多个服务器时:
#define QY_PRODUCT_VERSION 1// 1:表示正式服务器2:表示测试服务器 其他:...
#if QY_PRODUCT_VERSION == 1
#define URLHead @"正式服务器地址"
#define QYAccessKey @""
#define JG_appKey @""
#elif QY_PRODUCT_VERSION == 2
#define URLHead @"测试服务器地址"
#define QYAccessKey @""
#define JG_appKey @""
#elif QY_PRODUCT_VERSION == ...
#else
#define URLHead @"其他服务器地址"
#define QYAccessKey @""
#define JG_appKey @""
#endif
简单的打印log日志
#ifdef DEBUG
#define QYLog(...) NSLog(__VA_ARGS__)
#else
#define QYLog(...)
#endif
屏幕尺寸
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
设备类型
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define IS_SUPER_RETINA ([[UIScreen mainScreen] scale] == 3.0)
屏幕类型
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
#define IS_IPHONE_X (IS_IPHONE && SCREEN_MAX_LENGTH == 812.0)
#define IS_IPHONE_XR (IS_IPHONE && SCREEN_MAX_LENGTH == 896.0 && IS_RETINA)
#define IS_IPHONE_XS_MAX (IS_IPHONE && SCREEN_MAX_LENGTH == 896.0 && IS_SUPER_RETINA)
底部tabbar增加的高度
#define TabBarHeightAdded \
({ \
CGFloat addedH = 0; \
if (IS_IPHONE_X) { \
addedH = 34; \
} else if (IS_IPHONE_XR) { \
addedH = 34; \
} else if (IS_IPHONE_XS_MAX) { \
addedH = 34; \
} \
(addedH); \
}) \
状态栏高度
#define phoneStatusHeight \
({ \
CGFloat addedH = 20; \
if (IS_IPHONE_X) { \
addedH = 44; \
} else if (IS_IPHONE_XR) { \
addedH = 44; \
} else if (IS_IPHONE_XS_MAX) { \
addedH = 44; \
} \
(addedH); \
}) \
适配比例
// 适配比例 (UI效果图以 iPhone 6 (375x667)屏幕像素大小为尺寸基础时)
#define WIDTH_SCALE [UIScreen mainScreen].bounds.size.width/375.0
#define HEIGHT_SCALE [UIScreen mainScreen].bounds.size.height/667.0
#define NAVIGATION_BAR_HEIGHT (IS_IPHONE_X || IS_IPHONE_XR || IS_IPHONE_XS_MAX ? 88.0 : 64.0)
#define TAB_BAR_HEIGHT (IS_IPHONE_X || IS_IPHONE_XR || IS_IPHONE_XS_MAX ? (49.0 + 34.0) : 49.0)
颜色
#define RGBA_COLOR(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
//16进制颜色
#define UIColorFromHex(s) [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s &0xFF00) >>8))/255.0 blue:((s &0xFF))/255.0 alpha:1.0]
弱引用
#define TYPE_WEAK_SELF __weak typeof(self) weakSelf = self
判断空值
#define IS_NULL_STRING(String) ([String isKindOfClass:[NSNull class]] || String == nil || [String isEqualToString:@""])
防止循环引用
#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
使用方式:
@weakify(self);
numblcok = ^{
@strongify(self);
self.blackView = ...;
}
拉伸图片的一部分,其他不变
UIImage *img = [UIImage imageNamed:@"pop"];
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 40) resizingMode:UIImageResizingModeStretch];
self.imgView.image = img;
平铺图片,就是一张小图可以平铺在一起形成一张图
UIImage *img = [UIImage imageNamed:@"pop"];
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 12) resizingMode:UIImageResizingModeTile];
self.imgView.image = img;
生成一个二维码链接直接跳转App Store下载某个APP
https://itunes.apple.com/cn/app/idxxxxx
填上你APP 的id即可
查看appid
进入苹果开发者账号->App Store Connect ->我的app ->app 信息 - > appid