ios 常用宏

//

//  CommonMacro.h

//

//

//  Created by liman on 14-7-22.

//  Copyright (c) 2014 chinamworld. All rights reserved.

//

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

#import <CoreTelephony/CTCarrier.h>

//常用的IOS开发宏

#pragma mark - 界面部分

#define NavigationBar_HEIGHT 44     //导航控制器

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)      //屏幕宽度

#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)    //屏幕高度

#define SCREEN_HEIGHT_IPHONE_4() ([UIScreen mainScreen].bounds.size.height) == 480

#define SCREEN_HEIGHT_IPHONE_5_6() ([UIScreen mainScreen].bounds.size.height) == 568

#define RGBCOLOR(r,g,b)    [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1.000]

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

// rgb颜色转换(16进制->10进制)

#define HexColor(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]

#pragma mark - 系统部分

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]   //当前设备的系统版本

#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])     //当前的系统版本

#define IOS_VERSION_6() ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) && ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)

#define IOS_VERSION_7() ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) && ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)

#define IOS_VERSION_8() [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])   //当前的设备的默认语言

#define isRetina ([[UIScreen mainScreen] scale]== 2 ? YES : NO)    //是否是高清屏

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)    //是否是IPhone5

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //是否是IPAD

#pragma mark - Block

#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

#pragma mark - 图片,返回UIImage

#define LoadCacheImage(name) [UIImage imageNamed:name] // 读取图片(最常用)

#define LoadDiskImage(name)  [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:nil]]

#define USER_DEFAULT [NSUserDefaults standardUserDefaults]      //UserDefault

#define degreesToRadian(x) (M_PI * (x) / 180.0) //弧度转角度

#define radianToDegrees(radian) (radian*180.0)/(M_PI)  //角度转弧度

//读取本地图片的imageNamed一样,但是性能比后者要强很多,两个参数,前面一个是文件名,后面一个是类型

#define LoadImage(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]  //可以用来直接传图片名字

#define LoadImageWithType(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

#pragma mark - Path

#define kHomePath        NSHomeDirectory()

#define kCachePath      [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]

#define kDocumentFolder [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#define kDocumentFolder2 [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

#define kLibraryPath [NSHomeDirectory() stringByAppendingPathComponent:@"Library"]

#define kTempPath    NSTemporaryDirectory()

#define kMainBoundPath [[NSBundle mainBundle] bundlePath]

#define kResourcePath  [[NSBundle mainBundle] resourcePath]

#define kExecutablePath [[NSBundle mainBundle] executablePath]

#pragma mark - Setting

//当前系统设置国家的country iso code

#define countryISO  [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]

//当前系统设置语言的iso code

#define languageISO [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]

staticNSString *(^CountryNameByISO)(NSString *) = ^(NSString *iso) {

    NSLocale *locale = [NSLocalecurrentLocale];

    return [locale displayNameForKey:NSLocaleCountryCodevalue:iso];

};

staticNSString *(^ISOCountryCodeByCarrier)() = ^() {

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfoalloc] init];

    CTCarrier *carrier = [networkInfo subscriberCellularProvider];

    return [carrier isoCountryCode];

};

#define SIMISO                  ISOCountryCodeByCarrier()

#define CountryNameFromISO(iso) CountryNameByISO(iso)

//针对真机iPhone

#if TARGET_OS_IPHONE

//iPhone Device

#endif

//针对模拟器

#if TARGET_IPHONE_SIMULATOR

//iPhone Simulator

#endif

//ARC

#if __has_feature(objc_arc)

//compiling with ARC

#define SAFE_RELEASE(x) x = nil

#else

// compiling without ARC

#define SAFE_RELEASE(x) [x release];x=nil

#endif

// 注释下行则不打印日志

#define __SHOW__DLog__

#ifdef __SHOW__DLog__

#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )

#else

#define DLog( s, ... ) {}

#endif

时间: 2024-10-10 16:56:25

ios 常用宏的相关文章

ios 常用宏(copy)

分享一下我现在用的 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 // // #ifndef VIP_O

iOS 常用宏定义

下面是在iOS开发中常用的一些宏定义: //一般的提示信息 #define mAlertView(title, msg) \ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; #define SYSTEM_VERSION_GREATER_TH

(转)iOS 常用宏定义

#ifndef MacroDefinition_h #define MacroDefinition_h //-------------------获取设备大小------------------------- //NavBar高度 #define NavigationBar_HEIGHT 44 //获取屏幕 宽度.高度 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UI

iOS常用宏定义

//-------------------获取设备大小------------------------- //NavBar高度 #define NavigationBar_HEIGHT 44 //获取屏幕 宽度.高度 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) //-----------

IOS常用宏定义1

#ifndef MacroDefinition_h #define MacroDefinition_h //-------------------获取设备大小------------------------- //NavBar高度 #define NavigationBar_HEIGHT 44 //获取屏幕 宽度.高度 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UI

iOS 开发常用宏

来源:iOS_小松哥 链接:http://www.jianshu.com/p/be00c3f3cafd 大家都是知道使用宏不仅方便,而且可以提高开发效率.下面总结了iOS开发过程中的一些常用宏,会持续的往里面添加. //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO ) //数组是否为空 #define kArr

iOS重用宏定义

iOS 多快好省的宏(转) 原文地址:http://my.oschina.net/yongbin45/blog/150149 // 字符串: #ifndef nilToEmpty #define nilToEmpty(object) (object!=nil)?object:@"" #endif #ifndef formatStringOfObject #define formatStringOfObject(object) [NSString stringWithFormat:@&q

常用宏

#define NavigationBar_HEIGHT 44 #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]] //读取本地图片的 和imageNamed一样,但是性能比后者要强很多,两个参数,前面一个是 文件名,后面一个是类型 //例如 imageView.image =  LOADIMAGE(@"文件名&qu

iOS常用控件尺寸大集合

元素控件 尺寸(pts) Window(含状态栏) 320 x 480 Status Bar的高度 20 Navigation Bar的高度 44 含Prompt的Navigation Bar的高度 74 Navigation Bar的图标 20×20(透明的png) Tool Bar的高度 44 Tool Bar的图标 20×20(透明的png) Tab Bar的高度 49 Tab Bar的图标 30×30(透明的png) 竖直时键盘的高度 216.252(iOS 5+的中文键盘) 水平时键盘