简单的宏定义(不定期补充)

  • 控制台输出
#if DEBUG
#define DSLog(FORMAT, ...) fprintf(stderr,"\%s [第%d行] %s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define DSLog(FORMAT, ...)
#endif
  • RGB色值
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r, g, b)      RGBA(r,g,b,1.0f)
  • 格式化字符串
#define kString(...) [NSString stringWithFormat:__VA_ARGS__]
  • 格式化字符串
#define kURLFromString(url) [NSURL URLWithString:url]
  • 输出点、坐标、Rect
#define DSLogPoint(p)     NSLog(@"%.2f,%.2f", p.x, p.y);
#define DSLogSize(size) NSLog(@"%.2f,%.2f", size.width, size.height);
#define DSLogRecT(p)       NSLog(@"%.2f,%.2f %.2f,%.2f", p.origin.x, p.origin.y, p.size.width, p.size.height);
  • 格式化数字
#define kDoubleToString(double) [NSString stringWithFormat:@"%.2f",double]
#define kIntToString(intValue)  [NSString stringWithFormat:@"%i",intValue]
#define kIntegerToString(value) [NSString stringWithFormat:@"%ld",(long)value]
#define kLongToString(value)    [NSString stringWithFormat:@"%lli",(long long)value]
#define kFloatToString(float)   [NSString stringWithFormat:@"%.0f",float]
#define kObjToString(obj)       [NSString stringWithFormat:@"%@",obj]

你可能感兴趣的:(简单的宏定义(不定期补充))