1. 程式人生 > >IOS中幾個常用的巨集

IOS中幾個常用的巨集

//RGB直接轉UIColor,方便死了有木有。這個是從破船blog裡面學習到的,船哥不要K我啊。。
#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]
 
//嘎嘎,自己定義的彈出Alert框和HUD
#define showAlert(_msg){UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:_msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"確定",nil];[alert show];}
#define showHUDInfo(text){self.HUD = [[MBProgressHUD alloc] initWithView:self.view];[self.view addSubview:self.HUD];self.HUD.delegate = self;self.HUD.mode = MBProgressHUDModeText;self.HUD.labelText = text;[self.HUD showAnimated:YES whileExecutingBlock:^{sleep(2);}completionBlock:^{[self.HUD removeFromSuperview];self.HUD = nil;}];}
 
//iOS7相容要用的,後面7.0替換一下可以改成任意版本。
#define ISIOS7  ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
 
//判斷是iphone還是ipad
#define IS_PAD     ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
#define IS_PHONE   ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)