IOS开发,知识点小结,ios开发中经常使用的宏定义总结

IOS开发,从应用跳转到用浏览器打开网页:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.oatos.com/bbs/"]];

用一个Button覆盖整个cell,加入动作

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
        title = NSLocalizedString(@"Pad_setting_logoutBtnTitle", nil);
#endif
        [btn setBackgroundImage:[UIImage imageNamed:@"bgBtnLogoutNormal.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;

经常使用的宏定义

#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) >> 16))/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) // 状态栏和导航栏的总高度 #define kPadHeightNavForPopView 44 //3.4版本号后開始使用的,重构后机制不一样(跟弹出层布局相关) #define kStatusBarFix (IsiOS7Later ? 20 : 0) // 状态栏高度 #define kPadHeightStatusAndNav (IsiOS7Later ? 64 : 0) // 状态栏和导航栏的总高度 #define kPadNaviBarHeight (IsiOS7Later ?

54.0f : 0) // pad不含状态栏的导航栏的高度 #define kPadBottomBarHeight 60.0f #define kPadHeightNav (IsiOS7Later ? 44 : 0)


小结:代码中,尽量不要用写死的数据,不然版本号适配以及以后的优化是非常痛苦的事情。

还实用宏定义能够简化代码。眼下我的理解仅仅有这么多。希望以后对这个掌握的更好。尽管这仅仅是小基础。可是也是一种良好的编程习惯。一个好的開始。

原文地址:https://www.cnblogs.com/jzssuanfa/p/6806908.html