// 安全釋放
#define release_safely(__pointer) do{[__pointer release],__pointer = nil;} while(0)
// 螢幕的實體高度
#define screenheight [uiscreen mainscreen].bounds.size.height
// 螢幕的實體寬度
#define screenwidth [uiscreen mainscreen].bounds.size.width
// 調試
#define nslog_function nslog(@"%s,%d",__function__,__line__)
//----------------------圖檔————————————————————————————————————————
//讀取本地圖檔
#define loadimage(file,ext) [uiimage imagewithcontentsoffile:[[nsbundle mainbundle]pathforresource:file oftype:ext]]
//定義uiimage對象
#define image(a) [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:a oftype:nil]]
#define imagenamed(_pointer) [uiimage imagenamed:_pointer]
//———————————————————————顔色類———————————————————————————-----—————————————
// rgb顔色轉換(16進制->10進制)
#define uicolorfromrgb(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]
//帶有rgba的顔色設定
#define color(r, g, b, a) [uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
// 擷取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 background_color [uicolor colorwithred:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
//清除背景色
#define clearcolor [uicolor clearcolor]
#pragma mark - color functions
#define rgbcolor(r,g,b) [uicolor colorwithred:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define rgbacolor(r,g,b,a) [uicolor colorwithred:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
//———————————————————————tag宏———————————————————————————-----—————————————
//viewwithtag
#define viewwithtag(_object, _tag) [_object viewwithtag : _tag]
//———————————————————————單例模式宏———————————————————————————-----—————————————
//.h檔案處的聲明
#define define_singleton_for_header(classname) \
\
+ (classname *)shared##classname;
//.m檔案處的聲明
#define define_singleton_for_class(classname) \
+ (classname *)shared##classname { \
static classname *shared##classname = nil; \
static dispatch_once_t oncetoken; \
dispatch_once(&oncetoken, ^{ \
shared##classname = [[self alloc] init]; \
}); \
return shared##classname; \
}
//———————————————————————單例模式———————————————————————————-----—————————————
static databasehandle * handle = nil;
+ (databasehandle *)shareinstance
{
@synchronized(self){
if (!handle) {
handle = [[databasehandle alloc] init];
}
}
return handle;
—————————————不用你把所有nslog的删除或注釋,直接修改#if 判斷的值就行了(1執行,0不執行)——————————————
#if 1
#define nslog(format, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[nsstring stringwithutf8string:__file__] lastpathcomponent] utf8string], __line__, [[nsstring stringwithformat:format, ##__va_args__] utf8string]);
#else
#define nslog(format, ...) nil
#endif
#define need_output_log 0
#if need_output_log
#define slog(xx, ...) nslog(xx, ##__va_args__)
#define sllog(xx, ...) nslog(@"%s(%d): " xx, __pretty_function__, __line__, ##__va_args__)
#define sllogrect(rect) \
sllog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, \
rect.size.width, rect.size.height)
#define sllogpoint(pt) \
sllog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)
#define sllogsize(size) \
sllog(@"%s w=%f, h=%f", #size, size.width, size.height)
#define sllogcolor(_color) \
sllog(@"%s h=%f, s=%f, v=%f", #_color, _color.hue, _color.saturation, _color.value)
#define sllogsuperviews(_view) \
{ for (uiview* view = _view; view; view = view.superview) { sllog(@"%@", view); } }
#define sllogsubviews(_view) \
{ for (uiview* view in [_view subviews]) { sllog(@"%@", view); } }
#define slog(xx, ...) ((void)0)
#define sllog(xx, ...) ((void)0)
#endif