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)

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值