由于在项目经常需要用到一些方法,每次都写那么长一串比较麻烦,所以就写了一个.h文件,定义了一些常用方法的宏:
文件名:UtilityMacro.h
//
// UtilityMacro.h
// UtilityClass
//
// Created by mrj on 12-7-8.
// Copyright (c) 2013年 极致. All rights reserved.
//
#ifndef UtilityClass_Macro_h
#define UtilityClass_Macro_h
#define ALog(fmt,...) NSLog((@"ALog: %s [Line %d] \n" fmt), __PRETTY_FUNCTION__, __LINE__,##__VA_ARGS__);
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define FLOG(str, args...) NSLog\
(@"[文件:%s] [行号:%d] [类:%@] [方法:%s]\n%@", strrchr(__FILE__, '/'), __LINE__, [self class], sel_getName(_cmd),\
[NSString stringWithFormat:str , ##args ])
#define FASSERT(condition, str, args...) NSAssert\
(condition, @"--------------------------------------------------------------------------------\
\n[文件:%s] [行号:%d] [类:%@] [方法:%s]\n%@", strrchr(__FILE__, '/'), __LINE__, [self class], sel_getName(_cmd),\
[NSString stringWithFormat:str , ##args ])
#define ResourcePath [[NSBundle mainBundle] resourcePath] //获取自定义文件的bundle路径
#define ImageNamed(name) [UIImage imageWithContentsOfFile:[ResourcePath stringByAppendingPathComponent:name]]
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1] //RGB进制颜色值
#define HexColor(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:1.0] //16进制颜色值,如:#000000 , 注意:在使用的时候hexValue写成:0x000000
#endif
需要使用的时候把它写入到:Supporting Files ---> *-Prefix.pch文件里面(示例如下):
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "UtilityMacro.h"
#import "NotificationName.h"
#endif