iOS常用的宏

 
 
//
// CommonMacro.h
//
//
// Created by Haven on 26/9/13.
// Copyright (c) 2013 LF. 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 RBGCOLOR(r,g,b) [UIColor colorWithRed:0.400 green:0.523 blue:0.949 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 IS_IOS6() [[[UIDevice currentDevice] systemVersion] floatValue] >= 6.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]
 
static NSString *(^CountryNameByISO)(NSString *) = ^(NSString *iso) {
NSLocale *locale = [NSLocale currentLocale];
return [locale displayNameForKey:NSLocaleCountryCode value:iso];
};
 
static NSString *(^ISOCountryCodeByCarrier)() = ^() {
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
return [carrier isoCountryCode];
};
 
#define SIMISO ISOCountryCodeByCarrier()
#define CountryNameFromISO(iso) CountryNameByISO(iso)
 
 
#pragma mark - 单例
#define DeclareSingletonInterface(className) \
+ (classname *)shared##classname
 
#define ImplementSingletonInterface(className) \
+ (classname *)shared##classname { \
static dispatch_once_t onceToken = 0; \
static id sharedInstance = nil; \
dispatch_once(&onceToken, ^{ \
sharedInstance = [[self alloc] init]; \
}); \
return sharedInstance; \
}
 
 
#pragma mark - 功能部分
#ifdef DEBUG
# define DLog(...) NSLog((@"%s [Line %d] %@"), __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])
# define SLog(...) NSLog(__VA_ARGS__)
#else
# define DLog(...)
# define SLog(...)
#endif
//SLog(kMainBoundPath, nil);
 
//针对真机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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值