iOS Common macros

Source: Internet
Author: User

//

CommonMacro.h

//

//

Created by Liman on 14-7-22.

//Copyright (c) year Chinamworld. All rights reserved.

//

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

#import <CoreTelephony/CTCarrier.h>

// used in IOS development Macros

#pragma mark- Interface section

#define Navigationbar_height / / navigation controller

#define SCREEN_WIDTH ([UIScreen mainscreen].bounds.size.width) // screen width

#define Screen_height ([UIScreen mainscreen].bounds.size.height) // screen 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 color conversion ( + binary ->10 binary)

#define HEXCOLOR (rgbvalue) [Uicolor colorwithred: ((float) ((Rgbvalue & 0xFF0000) > > ) /255.0 Green: ((float) ((Rgbvalue & 0xff00 ) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF)/255.0 Alpha:1.0]

#pragma mark- System Section

#define Ios_version [[[Uidevice Currentdevice] systemversion] Floatvalue] // system version of the current device

#define Currentsystemversion ([[Uidevice Currentdevice] systemversion]) // current system version

#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:nsnumeric Search] = = nsorderedsame)

#define System_version_greater_than (v) ([[[Uidevice Currentdevice] systemversion] compare:v options:nsnumeric Search] = = 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:nsnumeric Search] = = nsorderedascending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]! = nsordereddescending)

#define CURRENTLANGUAGE ([[Nslocale preferredlanguages] Objectatindex:0]) // The default language for the current device

#define Isretina ([[UIScreen mainscreen] scale]== 2 ? Yes:no) // is the HD screen

#define IPHONE5 ([UIScreen instancesrespondtoselector: @selector (currentmode)]? Cgsizeequaltosize (Cgsizemake (640, 1136), [[UIScreen Mainscreen] currentmode].size): NO) // Whether it is IPhone5

#define ISPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad) // Whether it is an 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- picture, back to UIImage

#define LOADCACHEIMAGE (name) [UIImage Imagenamed:name] // Read pictures ( most commonly used )

#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) // radian turn angle

#define Radiantodegrees (radian) (radian*180.0)/(M_PI) / / angle to radians

// read the local picture same as imagenamed, but the performance is much stronger than the latter, two parameters, the previous one is the file name, followed by a type

#define LoadImage (_pointer) [UIImage imagenamed:[uiutil Imagename:_pointer] // can be used to directly upload the name of the picture

#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 for the current system settings Country

#define COUNTRYISO [[Nslocale Currentlocale] Objectforkey:nslocalecountrycode]

// ISO code for the current system Setup language

#define LANGUAGEISO [[Nslocale Currentlocale] Objectforkey:nslocalelanguagecode]

Static nsstring * (^countrynamebyiso) (nsstring *) = ^ ( NSString *iso) {

nslocale *locale = [nslocalecurrentlocale];

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)

// iPhone for real computer

#if Target_os_iphone

IPhone Device

#endif

// for simulators

#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

// Note the following line does not print the log

#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 Common macros

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.