iOS summary _#define macro definitions for specific use in iOS development

Source: Internet
Author: User

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

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.