ios 常用宏

來源:互聯網
上載者:User

標籤:des   io   ar   color   os   sp   for   strong   on   

//

//  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

ios 常用宏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.