iOS development, Knowledge Point Summary, summary of macro definitions commonly used in IOS development

Source: Internet
Author: User

iOS development, jump from app to open Web page in browser:

[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "http://www.oatos.com/bbs/"];

Overwrites the entire cell with a button, adding an action

Cell.accessorytype = Uitableviewcellaccessorynone;        UIButton *btn = [[UIButton alloc] initwithframe:cgrectmake (0.0, 0.0, cell.contentView.frame.size.width, 54.0)];        Btn.autoresizingmask = Uiviewautoresizingflexiblewidth;        Btn.backgroundcolor = COLOR (243.0, 89.0, 31.0, 1.0);        Btn.tag = 1003; NSString *title = nil, #ifndef appstore title = nslocalizedstring (@ "Pad_setting_exitbtntitle", nil); #else tit Le = nslocalizedstring (@ "Pad_setting_logoutbtntitle", nil); #endif [btn setbackgroundimage:[uiimage imagenamed:@ "BgB        Tnlogoutnormal.png "] forstate:uicontrolstatenormal];        [Btn setbackgroundimage:[uiimage imagenamed:@ "Bgbtnlogouthover.png"] forstate:uicontrolstatehighlighted];        [Btn Settitle:title Forstate:uicontrolstatenormal];        Btn.titleLabel.font = [Uifont boldsystemfontofsize:20.0];        [btn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (LOGINOUBTNCLicked:) forcontrolevents:uicontroleventtouchupinside];        [Cell.contentview ADDSUBVIEW:BTN]; Cell.selectionstyle = Uitableviewcellselectionstylenone;

Common macro Definitions

#define Ios_version  [[Uidevice Currentdevice] deviceversion] #define Kdeviceagent [[Uidevice Currentdevice] DeviceAgent] #define Isios7later        ! ( Ios_version < 7.0) #define Is4inch            [oatosutils Is4inchscreen]


#define COLOR (r,g,b,a) [Uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] #define UICOLORFROMRGB ( Rgbvalue) [Uicolor colorwithred: ((float) ((Rgbvalue & 0xFF0000) >>))/255.0 Green: ((float) ((Rgbvalue & 0XFF00) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF)/255.0 alpha:1.0]


#define SIZE (W, h)                          Cgsizemake (W, h) #define Point (x, y) cgpointmake (x, y)                         #define Rect (x, Y, W, h)                    CGRectMake ( X, Y, W, h) #define Viewwidth (v)                        v.frame.size.width#define viewheight (v)                       (isios7later? V.frame.size.height: V.frame.size.height-statusbarheight) #define VIEWX (v)                            v.frame.origin.x#define viewy (v)                            v.frame.origin.y# Define Viewrect (v)                         Rect (Viewx (v), Viewy (v), Viewwidth (v), Viewheight (v)) #define Selfviewheight                      Self.view.bounds.size.height


#define KDEVICESCREENH                  [[UIScreen mainscreen] Bounds].size.height#define kdevicescreenw                  [[UIScreen Mainscreen] Bounds].size.width#define kappmainscreenframewidth        [[UIScreen mainscreen] applicationFrame]. Size.width#define kappmainscreenframeheight       [[UIScreen Mainscreen] Applicationframe].size.height

#define Statusbarheight                     [uiapplication sharedapplication].statusbarframe.size.height#define Kheightstatusandnav       (isios7later?  64:44)    ////status bar and navigation bar The total height of # define Kpadheightnavforpopview after           the//3.4 version is used, the refactoring mechanism is different (related to the popup layer layout) #define Kstatusbarfix             (isios7later?  20:0)     //status bar height # # Kpadheightstatusandnav    (isios7later?  64:0)    //status bar and navigation bar The total height of # define Kpadnavibarheight         (isios7later?  54.0f:0)               //pad height of the navigation bar without status bar # kpadbottombarheight                       60.0f#define kpadheightnav             (isios7later?  44:0)

Summary: In the code, try not to write dead data, or version adaptation and later optimization is very painful things. You can also use macro definitions to simplify your code. At present I understand only so much, hope later on this master better. Although this is only a small basis, but also a good programming habit, a good start.

iOS development, Knowledge Point Summary, summary of macro definitions commonly used 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.