General macro definition and header file of App development process, app

Source: Internet
Author: User

General macro definition and header file of App development process, app

To do well, you must first sharpen your tools.

Before officially implementing various cool functions and UIS, it is necessary to make preparations to improve the efficiency of subsequent development.

Therefore, I am not focusing on a variety of heap technologies in this series. I am more concerned with the "grain and grass line" before "Bing Ma Dong". It is a little complicated, but when the entire context is clearly understood, the subsequent work will only be infinitely scalable and optimized on a good foundation and framework.

 

Macro definition is an effective tool to improve efficiency in the development process. It is necessary to summarize some general macro definitions for simple and efficient use.

Some general macro definitions are sorted out as follows, which should be necessary for development:

# Pragma mark -- set the global size macro # define StatusBarHeight 20 # define NaviBarHeight 44 # define TabBarHeight 49 # define KeyboardEngHeight 216 # define KeyboardHansHeight 252 # pragma mark -- set the global color macro/, as a reference solution for device adaptation only # define StatusBarColor [UIColor blackColor] # define NaviBarColor [UIColor whiteColor] # define NaviBarTitleSelectedColor (255,120,100) # define NaviBarTitleUnselectedColor (100,100,100) # define NaviBarShadowColor COLOR (230,230,230) # define NaviBarTitleFontSize (DeviceIsNotRetina | DeviceIsiPhone4s | DeviceIsiPhone5 )? 17: 19) # define attributes [NSDictionary attributes: FONTAppliedFixed (attributes), NSFontAttributeName, identifier, identifier, nil] # define attributes (DeviceIsNotRetina | DeviceIsiPhone4s | DeviceIsiPhone5 )? 14: 16) # define NaviItemTextGrayColor (140,140,140) # define NaviBottomLineColor NaviBarTitleSelectedColor # pragma mark -- String localization macro # define LocalizedString (String) NSLocalizedString (String, String) # pragma mark -- obtains the width and height of a device. // changes with the horizontal and vertical screens inside the application. # define DeviceSize [UIScreen mainScreen]. bounds. size # define DeviceWidth DeviceSize. width # define DeviceHeight DeviceSize. height # pragma mark -- determines if iPhone 4, 4S, 5, 6, Plus, iPad // will not change with the internal landscape and landscape of the application # define DeviceCurrentModeSize [UIScreen mainScreen]. currentMode. size # define DevicePortraitModeSize (DeviceCurrentModeSize. width <DeviceCurrentModeSize? DeviceCurrentModeSize: CGSizeMake (DeviceCurrentModeSize. height, DeviceCurrentModeSize. width) # define DeviceIsNotRetina complete (temperature, CGSizeMake (320,480) # define DeviceIsiPhone4s complete (temperature, CGSizeMake (640,960) # define DeviceIsiPhone5 temperature (temperature, CGSizeMake (640,113 6 )) // 6 s and 6 in the same size # define DeviceIsiPhone6 CGSizeEq UalToSize (DevicePortraitModeSize, CGSizeMake (750,133 4) // 6 s Plus and 6 Plus are of the same size (some models only have 6 s of bounds. size) # define DeviceIsiPhone6plus (CGSizeEqualToSize (DevicePortraitModeSize, CGSizeMake (1125,200 1) | CGSizeEqualToSize (batch, CGSizeMake (1242,220 8) // Debug on the simulator, possible non-Retina Resolution # define DeviceIsiPad (CGSizeEqualToSize (DevicePortraitModeSize, CGSizeMake (768,102 4) | CGSizeEqualToSize (Outputs, CGSizeMake (1536,204 8) | CGSizeEqualToSize (DevicePortraitModeSize, CGSizeMake (1024,136 6) | CGSizeEqualToSize (DevicePortraitModeSize, CGSizeMake (2048,273 2 ))) # pragma mark -- determines whether the device's OS has an integer version number. // The current OS version number is still floating-point # define DeviceIOSVersion [[[UIDevice currentDevice] systemVersion] floatValue] # define DeviceIOSVersionIs (x) (DeviceIOSVersion> = x & DeviceIOSVersion <x + 1? YES: NO) # define DeviceIOSVersionAbove (x) (DeviceIOSVersion> = x? YES: NO) # pragma mark-calculate the current scaling size in the annotation Graph Based on the device. The current scaling size (the image version: 375 width) is displayed on the iPad using the iPhone 6 standard. // The following macro definitions are displayed, as a reference solution for device adaptation only # define ResizeSideBase6 (s) (DeviceIsiPad? S: (DeviceWidth * s/375) # pragma mark -- scales proportionally only according to the width of the Design Drawing (marked image version: 375 width) # define ResizeSideBase375 (s) (DeviceWidth * s/375) # pragma mark -- set Custom font # define FontName1 @ "FZY3JW--GB1-0" // font name of the 正 ttf # define FontName2 @ "Helvetica" # define FontName3 @ "Helvetica-Bold "// fixed font size # define FONTAppliedFixed (n) [UIFont systemFontOfSize: n] # define FONTAppliedBoldFixed (n) [UIFont boldSystemFontOfSize: n] # define FONTFZZYF Ixed (n) [UIFont fontWithName: FontName1 size: n] # define FONTHelveticaFixed (n) [UIFont fontWithName: FontName2 size: n] # define transform (n) [UIFont fontWithName: fontName3 size: n] // The following macro definition is used as a reference solution for device adaptation only. // The display font is calculated based on the device. (image version: 375 width) the iPad is displayed on the iPhone 6 standard # define FONTAppliedBase6 (n) (DeviceIsiPhone6plus? FONTAppliedFixed (n + 0.5): (DeviceIsiPhone6 | DeviceIsiPad? FONTAppliedFixed (n): FONTAppliedFixed (n-1) # define FONTAppliedBoldBase6 (n) (DeviceIsiPhone6plus? FONTAppliedBoldFixed (n + 0.5): (DeviceIsiPhone6 | DeviceIsiPad? FONTAppliedBoldFixed (n): FONTAppliedBoldFixed (n-1) # define FONTHelveticaBase6 (n) (DeviceIsiPhone6plus? FONTHelveticaFixed (n + 0.5): (DeviceIsiPhone6 | DeviceIsiPad? FONTHelveticaFixed (n): FONTHelveticaFixed (n-1) # define FONTHelveticaBoldBase6 (n) (DeviceIsiPhone6plus? FONTHelveticaBoldFixed (n + 0.5): (DeviceIsiPhone6 | DeviceIsiPad? Merge (n): FONTHelveticaBoldFixed (n-1) # pragma mark -- load image macros (the following methods are frequent IO and images are not cached): # define LOADIMAGE (name) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: name ofType: nil] # define LOADIMAGEWITHTYPE (name, type) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: name ofType: type] # pragma mark -- set hexadecimal RGB color (Format: RRGGBB) # define COLORWITHRRGGBBA (RRGGBB, A) [UIColor colorWithRed :( (float) (RRGGBB & 0xFF0000)> 16)/255.0 green :( (float) (RRGGBB & 0xFF00)> 8)/255.0 blue :( (float) (RRGGBB & 0xFF)/255.0 alpha: A] # define COLORWITHRRGGBB (RRGGBB) COLORWITHRRGGBBA (RRGGBB, 1.0) # pragma mark -- set 10-digit RGB color # define COLORWITHRGBA (R, g, B, A) [UIColor colorWithRed: R/255.0 green: G/255.0 blue: B/255.0 alpha: A] # define COLOR (R, G, B) COLORWITHRGBA (R, G, B, 1.0) # define COLORWITHIMAGE (name) [UIColor colorWithPatternImage: LOADIMAGE (name)] # pragma mark -- angle radian conversion # define DegreesToRadian (x) (M_PI * x/180.0) # define RadianToDegrees (radian) (radian * 180.0/M_PI) # pragma mark -- log output control macro # ifdef DEBUG # define LOG (...) NSLog (_ VA_ARGS _); # define LOG_METHOD NSLog (@ "% s", _ func _); # else # define LOG (...); # define LOG_METHOD; # endif # pragma mark -- weak reference macro definition # define WS (weakSelf) _ weak typeof (self) weakSelf = self;

 

Description:
1. [UIScreen mainScreen]. bounds. size will change with the landscape and landscape, and [[UIScreen mainScreen] currentMode]. size will not change.

For example, if you select the project's General project landscape screen and run it on the iPhone 6 s, the project will start with a portrait screen (375,667). After the application is rotated to the landscape screen, the former will face up to 667,375 ); the latter is always)

2. When determining whether DeviceIsiPhone6plus is 6 plus, I encountered some testing machines with the actual resolution (1125,200 1). That is to say, bounds. size is (375,667). I guess it is a new machine.

3. When the DeviceIsiPad judges the iPad, there is an additional non-Retina resolution comparison. Because the debugging on iPad is only for iPhone applications, this type of resolution may occur.

4. The macro definitions of ResizeSide and FONT series provide a simple reference solution for code adaptation to multiple devices for width and FONT. Of course, the Masonry class library is the best solution for code Adaptation devices. It is only used for convenient use.

5. The LOADIMAGE macro definition uses frequent IO methods to load image resources, so as to avoid long memory cache usage. We recommend that you add attribute or variable reference when you want to retain the object.

6. If the macro definition is referenced, __weak typeof (self) weakSelf = self; the typeof statement can also be replaced with the old version _ typeof. However, we recommend that you use the new method, that is, typeof.

 

Record the use of custom Fonts

Previously, when the Info. plist file was configured, the font key-value pairs were added and can be used now.

1. First add the. ttf font to the project, and then add the following code under the UIAppFonts key in the Source code of the Info. plist file:

<key>UIAppFonts</key>    <array>        <string>fzzy.ttf</string>    </array>

Of course, you can also find the Fonts provided by application key in list mode, add an item, and enter the ttf file name.

2. Use the following code in a suitable place (for example, the proxy method after the application of AppDelegate starts:

for (NSString* familyName in [UIFont familyNames]) {        LOG(@"familyName : %@", familyName);        for (NSString* fontName in [UIFont fontNamesForFamilyName:familyName]) {            LOG(@"fontName : %@", fontName);        }    }

3. After running the application, you can view the font output log on the console. Since the fzzy font is used, the actual name should be similar. So I found a font name like FZY3JW--GB1-0.

4. You can view the FONTFZZYFixed macro font display effect.

It should be noted that, in the same font family, the font names, such as, bold, and italic, are all different font names, which can be understood as using different fonts. A ttf font file generally has only one font. You need to view the font log output on the console.

 

Use of header files

Create a header file in the Supporting Files directory:

I put the general macro definition into CommonHeader. h to facilitate unified management and expansion.

Similarly, different macro definitions are recommended for different header files, such as StringsHeader. h, ImagesHeader. h, and URLsHeader. h.

Finally, the reference of all header files is added to the PrefixHeader. h In the precompiled header file to take effect globally.

 

Base project Updated: git@github.com: ALongWay/base. git

Related Article

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.