IOS Universal macro defines an efficient global macro rollup

Source: Internet
Author: User

Recently in the construction of new projects, in order to facilitate the development, often use a number of macro definitions, combing the previous project used, and check out the gaps selected some of the network is relatively good, summed up a share to everyone.

/*************************** System Version *****************************/

Get the version of your phone system

#define Hitosystemversion [[[Uidevice Currentdevice] systemversion] floatvalue]

is iOS7 and above system

#define HITOIOS7 ([[Uidevice currentdevice].systemversion Doublevalue] >= 7.0)

is iOS8 and above system

#define HITOIOS8 ([[Uidevice currentdevice].systemversion Doublevalue] >= 8.0)

is iOS9 and above system

#define HITOIOS9 ([[Uidevice currentdevice].systemversion Doublevalue] >= 9.0)

is iOS10 and above system

#define HITOIOS10 ([[Uidevice currentdevice].systemversion Doublevalue] >= 10.0)

is iOS11 and above system

#define HITOIOS11 ([[Uidevice currentdevice].systemversion Doublevalue] >= 11.0)

/*************************** Sandbox path *****************************/

Sandbox path

#define Hitohomepath nshomedirectory ()

Get sandbox Document

#define Hitopathdocument [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) Firstobject]

Get sandbox Cache

#define Hitopathcache [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) FirstObject]

Get Sandbox Temp

#define HITOPATHTEMP nstemporarydirectory ()

/*************************** Print Log *****************************/

Output statement

#ifdef DEBUG

# define NSLOG (FORMAT, ...) printf ("[%s<%p> line number:%d]:\n%s\n", __function__,self,__line__,[[nsstring Stringwithformat:format, # #__VA_ARGS__] utf8string])

#else

# define NSLOG (FORMAT, ...)  

#endif

/*************************** System Height *****************************/

The width and height of the screen

#define HITOSCREENW [UIScreen mainscreen].bounds.size.width

#define HITOSCREENH [UIScreen mainscreen].bounds.size.height

Screen size

#define Hitoscreensize [UIScreen mainscreen].bounds

Scale width and height (divide by 6s)

#define Hitoactureheight (height) roundf (height/375.0 * hitoscreenw)

#define HITOACTUREWIDTH (Width) roundf (width/667.0 * hitoscreenh)

Height of status bar

#define Hitostatusbarheight [[UIApplication sharedapplication] Statusbarframe].size.height

Height of navigation bar

#define Hitonavbarheight 44.0

The height of the Iphonex-safearea

#define Hitosafeareaheight ([[UIApplication sharedapplication] statusbarframe].size.height>? :0)

Height of column +iphonex-safearea

#define Hitotabbarheight (49+hitosafeareaheight)

Navigation bar + status bar height

#define Hitotopheight (hitostatusbarheight + hitonavbarheight)

/*************************** view, class initialization *****************************/

Property Properties Quick Declaration

#define Hitopropertystring (s) @property (nonatomic,copy) NSString * s

#define Hitopropertynsinteger (s) @property (nonatomic,assign) nsintegers

#define HITOPROPERTYFLOAT (s) @property (nonatomic,assign) floats

#define Hitopropertylonglong (s) @property (nonatomic,assign) long long s

#define Hitopropertynsdictionary (s) @property (Nonatomic,strong) nsdictionary * s

#define Hitopropertynsarray (s) @property (Nonatomic,strong) Nsarray * s

#define Hitopropertynsmutablearray (s) @property (Nonatomic,strong) Nsmutablearray * s

Get information such as view width and height xy

#define HITOVIEWH (View1) view1.frame.size.height

#define HITOVIEWW (View1) view1.frame.size.width

#define HITOVIEWX (View1) view1.frame.origin.x

#define HITOVIEWY (View1) VIEW1.FRAME.ORIGIN.Y

Get Self.view's Wide height

#define HITOSELFVIEWW (Self.view.frame.size.width)

#define HITOSELFVIEWH (Self.view.frame.size.height)

Instantiation of

#define HITOVIEWALLOC (VIEW,X,Y,W,H) [[View Alloc]initwithframe:cgrectmake (x, Y, W, h)]

#define HITOALLOCINIT (controller,cname) Controller *cname = [[Controller alloc]init]

View fillet and Border

#define Hitoviewborderradius (View,radius,width,color) \

\

[View.layer Setcornerradius: (Radius)];\

[View.layer setmaskstobounds:yes];\

[View.layer setborderwidth: (Width)];\

[View.layer Setbordercolor:[color Cgcolor]]

View rounded Corners

#define Hitoviewradius (View,radius) \

\

[View.layer Setcornerradius: (Radius)];\

[View.layer Setmaskstobounds:yes]

/*************************** picture, color, font size *****************************/

Default picture

#define Hitoplaceholderimage [UIImage imagenamed:@"XXX"]

Defining UIImage Objects

#define HITOIMAGE (imageName) [UIImage imagenamed:[nsstring stringwithformat:@"%@", ImageName]]

Basic color

#define Hitoclearcolor [Uicolor Clearcolor]

#define Hitowhitecolor [Uicolor Whitecolor]

#define Hitoblackcolor [Uicolor Blackcolor]

#define Hitograycolor [Uicolor Graycolor]

#define Hitogray2color [Uicolor Lightgraycolor]

#define Hitobluecolor [Uicolor Bluecolor]

#define Hitoredcolor [Uicolor Redcolor]

Color A represents transparency, 1 is opaque, 0 is transparent

#define HITORGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]

RGB color conversion (16 binary->10)

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

Split Line Color

#define LineColor [Uicolor colorwithred:201/255.0 Green:201/255.0Blue:201/255.0 Alpha :0.2]

Bold

#define HITOBOLDSYSTEMFONTOFSIZE (FONTSIZE) [Uifont boldsystemfontofsize:fontsize]

Size

#define HITOSYSTEMFONTOFSIZE (FONTSIZE) [Uifont systemfontofsize:fontsize]

/*************************** notifications and local storage *****************************/

Create a notification

#define Hitoaddnotification (Selectorname,key) [[Nsnotificationcenter defaultcenter]addobserver:self selector:@ Selector (selectorname) Name:key Object:nil];

Send Notifications

#define HITOSENDNOTIFICATION (key) [[Nsnotificationcenter Defaultcenter] Postnotificationname:key object:self Userinfo:nil];

Remove notifications

#define HITOREMOVENOTIFICATION (key) [[Nsnotificationcenter defaultcenter]removeobserver:self Name:key Object:nil];

Localized storage

#define HITOUSERDEFAULTS (NSUSERDEFAULTS,DEFU) nsuserdefaults * Defu = [Nsuserdefaults standarduserdefaults];

/*************************** other *****************************/

Main Window

#define Hitoapplication [UIApplication Sharedapplication].keywindow

string concatenation

#define HITOSTRINGWITHFORMAT (Format,...) [NSString stringwithformat:format,# #__VA_ARGS__]

GCD code executes only once

#define HITODISPATCH_ONCE_BLOCK (onceblock) static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, Onceblock);

Strong references

#define HITOWEAKSELF __weak typeof (self) weakself = self;

Successful identification

#define Hitosuccess @"Success"

Failure ID

#define Hitofailure @"Failure"

Sign-in Status ID

#define HITOSUCTITLE @"Login Successful"

#define HITOFAITITLE @"Login Failed"

Network status identification

#define HITOFAINETWORK @"Network Error"

If the similarity is purely coincidental, if there is a mistake.

IOS Universal macro defines an efficient global macro rollup

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.