The following is just a suggestion, I hope that we have more suggestions, many errors, too simple macro use method does not explain, to point to expand the
No, no, it's like this before, every viewcontroller is going to write a repetitive code that's a lot more annoying.
/*********************** Pre-treatment *****************************/
UILabel *titlelabel = [[UILabel alloc] init];
Titlelabel. backgroundcolor = [uicolor clearcolor];
Titlelabel. textcolor = [uicolor redcolor];
Titlelabel. text = @ "Navigation bar title";
Titlelabel. font=[uifont fontwithname:nil size:17.0f];
[Titlelabel SizeToFit];
self. Navigationitem. Titleview = Titlelabel;
A macro is defined in the global configuration file (config.h)
#define Set_nav_title (_title) ({\
UILabel *titlelabel = [[UILabel alloc] Init];\
Titlelabel.backgroundcolor = [Uicolor clearcolor];\
Titlelabel.textcolor = [Uicolor redcolor];\
Titlelabel.text = _title;\
Titlelabel.font=[uifont fontwithname:nil Size:17.0f];\
[Titlelabel sizetofit];\
Self.navigationItem.titleView = titlelabel;\
})
After defining a macro, that's the sentence.
/*********************** after treatment *****************************/
set_nav_title(@ "navigation bar title");
//To ask you a question, how to pass an instance object in the macro inside, can realize
Finally, we introduce a fun, try to tune the very good, the following section of the code to copy to. PCH, you can see the effect when you print
A very advanced NSLog.
#define NSLOG (format, ...) do {\
fprintf (stderr, "<%s:%d>%s\n", \
[[[NSString stringwithutf8string:__file__] lastpathcomponent] utf8string], \
__line__, __func__); \
(NSLOG) (format), # #__VA_ARGS__); \
fprintf (stderr, "-------------------------------perfect split line---hehe----------------------------\ n"); \
} while (0)
iOS summary _#define macro definitions for specific use in iOS development