Definition of common macros

Source: Internet
Author: User
//// Bmdefineutils. h // sensoro Configuration Utility // @ discussion macro definition // created by skyming on 14-4-15. // copyright (c) 2014 sensoro. all rights reserved. // # ifndef # define # pragma mark-color // ---------------------- color samples // obtain the color -- rgba # define rgba (R, G, B, A) [uicolor colorwithred: r/255. 0f Green: G/255.0f Blue: B/255.0f ALPHA: A] // obtain the color -- RGB # define RGB (R, G, B) rgba (R, G, B, 1.0f) // obtain the color-hexadecimal (hexadecimal-> decimal) 0 xffeeaa # define uicolorfromrgb (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] // ------------------------ color ---------------------------- # pragma mark-screen //------------- --------- Screen detection // Retina screen judgment # define isretina ([[uiscreen mainscreen] scale] = 2) // pad device judgment -- XIB or storyboard # define ispad (ui_user_interface_idiom () = uiuserinterfaceidiompad) // 4.0 on-screen judgment # define isr4 ([uiscreen instancesrespondtoselector: @ selector (currentmode)]? Cgsizeequaltosize (cgsizemake (640,113 6), [[uiscreen mainscreen] currentmode]. size): No) // 3.5 on-screen judgment # define isnotr4 ([uiscreen instancesrespondtoselector: @ selector (currentmode)]? Cgsizeequaltosize (cgsizemake (640,960), [uiscreen mainscreen] currentmode]. size): No) // ---------------------- screen # pragma mark-System Version // ---------------------- System Version #// system version # define isios4 ([[uidevice currentdevice] systemversion] intvalue] = 4) # define isios5 ([[[uidevice currentdevice] systemversion] intvalue] = 5) # define isios6 ([[uidevice currentdevice] systemversion] intvalue] = 6) # define isafterios4 ([[[uidevice currentdevice] systemversion] intvalue]> = 4) # define isafterios5 ([[uidevice currentdevice] systemversion] intvalue]> = 5) # define isafterios6 ([[[uidevice currentdevice] systemversion] intvalue]> = 6) # define isafterios7 ([[uidevice currentdevice] systemversion] floatvalue]> = 7.0) # define ioscurrentversion ([[uidevice currentdevice] systemversion]) // -------------------- system version # pragma mark-screen size // -------------------- screen size limit // application size (excluding the status bar, the height of the status bar is not 20, so you need to know the specific size) # define kcontent_height ([uiscreen mainscreen]. applicationframe. size. height) # define kcontent_width ([uiscreen mainscreen]. applicationframe. size. width) # define kcontent_frame (cgrectmake (0, 0, kcontent_width, kcontent_height )) # define kcontent_centerx kcontent_width/2 # define kcontent_centery kcontent_height/2 // specify the screen size. // specify the screen size for the device. // specify the screen size for the device. bounds. size. height) # define kscreen_width ([uiscreen mainscreen]. bounds. size. width) # define kscreen_frame (cgrectmake (0, 0, kscreen_width, kscreen_height )) # define kscreen_centerx kscreen_width/2 # define kscreen_centery kscreen_height/2 // -------------------- backup screen size ## Pragma mark-frame // adjust frame preview // obtain frame X, Y coordinate # define frame_tx (FRAME) (frame. origin. x) # define frame_ty (FRAME) (frame. origin. y) // obtain the width and height of the frame # define frame_w (FRAME) (frame. size. width) # define frame_h (FRAME) (frame. size. height) // -------------------- frame # pragma mark-uiview frame // ------------------------ uiview frame watermark // obtain the X and Y coordinates of the uiview frame # define view_tx (View) (view. frame. origin. x) # define view_ty (View) (view. frame. origin. y) // obtain the width and height of the uiview frame # define view_w (View) (view. frame. size. width) # define view_h (View) (view. frame. size. height) // fixed uiview frame height // fixed screen height # define ui_navigation_bar_height 44 # define ui_tool_bar_height 44 # define ui_tab_bar_height 49 # define height 20 // fixed screen height -------------------------- # pragma mark ---- file path // ------------------------ file path ---------------------------- // file-related path # define path_of_app_home nshomedirectory () # define path_of_temp nstemporarydirectory () # define path_of_document [attributes (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex: 0] # define attributes [attributes (nscachesdirectory, attributes, yes) objectatindex: 0] # define path_of_librarydirectory [attributes (nslibrarydirectory, nsuserdomainmask, yes) objectatindex: 0] # define documentssubdirectory (DIR) [[attributes (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex: 0] attributes: dir] # define librarysubdirectory (DIR) [using (nslibrarydirectory, nsuserdomainmask, yes) objectatindex: 0] Using: Dir] # define cachesubdirectory (DIR) [[using (nscachesdirectory, nsuserdomainmask, yes) objectatindex: 0] stringbyappendingpathcomponent: Dir] # define tempsubdirectory (DIR) [nstemporarydirectory () stringbyappendingpathcomponent: dir] // ---------------------- file path ---------------------------- # pragma mark-custom output // ------------------------ custom output outputs // custom output # ifdef debug # define mylog (...) nslog (_ va_args _) // rewrite nslog. Print the log and current number of lines in debug mode # define nslog (format ,...) fprintf (stderr, "\ nfunction: % s line: % d content: % s \ n", _ FUNCTION __, _ line __, [[nsstring stringwithformat: format, ##__ va_args _] utf8string]); // print the log in debug mode. A warning is displayed for the current row. # define ulog (FMT ,...) {uialertview * Alert = [[uialertview alloc] initwithtitle: [nsstring stringwithformat: @ "% s \ n [line % d]", _ pretty_function __, _ line _] Message: [nsstring stringwithformat: FMT, ##__va_args _] delegate: Nil cancelbuttontitle: @ "OK" otherbuttontitles: Nil]; [alert show] ;}# else # define mylog (...) # define ulog (...) # endif // output frame (frame is a struct and cannot be % @) # define logrect (f) nslog (@ "rect: \ NX: % F \ NY: % F \ nwidth: % F \ nheight: % F \ n ", F. origin. x, F. origin. y, F. size. width, F. size. height) // output bool value # define logbool (B) nslog (@ "% @", [email protected] "yes": @ "no "); // method of the output object # define dnslogmethod nslog (@ "[% s] % @", class_getname ([self class]), nsstringfromselector (_ cmd )); // point # define dnslogpoint (p) nslog (@ "% F, % F", p. x, p. y); // size # define dnslogsize (p) nslog (@ "% F, % F", p. width, P. height); // ---------------------- custom output bytes // ------------------------ memory ------------------------------ // use arc and do not use arc # If _ has_feature (objc_arc) // compiling with arc # else // compiling without arc # endif # pragma mark-common functions # define release_safely (_ pointer) {[_ pointer release]; _ pointer = nil;} // release an object # define safe_delete (p) if (p) {[P release], P = nil;} # define safe_release (X) [x release]; X = nil // ---------------------- memory usage // ---------------------- image reading // read local images # define LoadImage (file, ext) [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource: file oftype: ext] // defines the uiimage object # define image (a) [uiimage imagewithcontentsoffile: [[nsbundle mainbundle] pathforresource: A oftype: nil] // define the uiimage object # define imagenamed (_ pointer) [uiimage imagenamed: [uiutil imagename: _ pointer] // we recommend that you use the first two macro definitions, higher performance than the latter // ---------------------- image placement // proxy # define appdelegate [uiapplication sharedapplication] Delegate] // obtain the current language # define currentlanguage ([[nslocale preferredlanguages] objectatindex: 0]) // 正 simplified font definition # define font (f) [uifont fontwithname: @ "FZHTJW--GB1-0" Size: F] // set the tag attribute of view # define viewwithtag (_ object, _ Tag) [_ OBJECT viewwithtag: _ Tag] // localized program, referencing an international file # define mylocal (x ,...) nslocalizedstring (x, nil) // G-C-D # define back (Block) dispatch_async (dispatch_get_global_queue (queue, 0), block) # define main (Block) dispatch_async (blocks) // nsuserdefaults instantiation # define user_default [nsuserdefaults standarduserdefaults] // obtain the radians and radians from the angle to obtain the angle # define degreestoradian (x) (m_pi * (X)/180.0) # define radiantodegrees (radian) (radian * 180.0)/(m_pi) # pragma mark-Action // Openurl # define canopenurl (appscheme) ([[uiapplication sharedapplication] canopenurl: [nsurl urlwithstring: appscheme]) # define Openurl (appscheme) ([[uiapplication sharedapplication] Openurl: [nsurl urlwithstring: appscheme]) // telphone # define Cantel ([[uiapplication sharedapplication] canopenurl: [nsurl urlwithstring: @ "Tel:"]) # define Tel (phonenumber) ([[uiapplication sharedapplication] Openurl: [nsurl urlwithstring: [nsstring stringwithformat: @ "Tel: % @", phonenumber]) # define telprompt (phonenumber) ([[uiapplication sharedapplication] Openurl: [nsurl urlwithstring: [nsstring stringwithformat: @ "telprompt: % @", phonenumber] // pop-up information # define alert (MSG) [[[uialertview alloc] initwithtitle: Nil message: MSG delegate: Nil cancelbuttontitle: @ "OK" otherbuttontitles: nil] Show]/* is used to save the last line of the singleton code. Do not add * // ---------------------------- Single Grain ------------------------ // @ interface # define singleton_interface (classname) + *) shared ## classname; // @ implementation # define singleton_implementation (classname) Static classname * _ instance; + (ID) allocwithzone :( nszone *) Zone {static dispatch_once_t oncetoken; dispatch_once (& oncetoken, ^ {_ instance = [Super allocwithzone: Zone] ;}); return _ instance ;}+ (classname *) shared # classname {static dispatch_once_t oncetoken; dispatch_once (& oncetoken, ^ {_ instance = [[self alloc] init] ;}); return _ instance ;}// ---------------------- Single Grain ------------------------------ # endif

  

Definition of 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.