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)

小结:代码中,尽量不要用写死的数据,不然版本适配以及以后的优化是很痛苦的事情。还有用宏定义可以简化代码。目前我的理解只有这么多,希望以后对这个掌握的更好。虽然这只是小基础,但是也是一种良好的编程习惯,一个好的开始。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。