新浪微博加号按钮OC代码
2017-08-31 20:47
239 查看
#import "WBTabBar.h" @interface WBTabBar() /// 加号按钮 @property(nonatomic,weak) UIButton *plusBtn; @end @implementation WBTabBar -(instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ // 添加一个+号按钮 到tabbar中 UIButton *plusBtn = [[UIButton alloc] init]; // 设置背景 [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal]; [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted]; // 增加+号图片 [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal]; [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted]; // 大小 [plusBtn sizeToFit]; // 监听事件 [plusBtn addTarget:self action:@selector(plusClick) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:plusBtn]; self.plusBtn = plusBtn; } return self; } // 加号按钮点击事件 - (void)plusClick{ NSLog(@"加号按钮被点击了"); } // 标签按钮布局 - (void)layoutSubviews{ [ super layoutSubviews ]; // 加号按钮居中显示 self.plusBtn.translatesAutoresizingMaskIntoConstraints = false; //水平居中 NSLayoutConstraint *plusBtn_CenterX = [self.plusBtn.centerXAnchor constraintEqualToAnchor:self.centerXAnchor]; //垂直居中 NSLayoutConstraint *plusBtn_CenterY = [self.plusBtn.centerYAnchor constraintEqualToAnchor:self.centerYAnchor]; //宽度约束 NSLayoutConstraint *plusBtn_Width = [self.plusBtn.widthAnchor constraintEqualToConstant:64]; //高度约束 NSLayoutConstraint *plusBtn_Height = [self.plusBtn.heightAnchor constraintEqualToConstant:44]; [NSLayoutConstraint activateConstraints:@[plusBtn_CenterX,plusBtn_CenterY,plusBtn_Width,plusBtn_Height]]; } /// 其他按钮尺寸及位置 // 按钮索引 CGFloat index = 0; // 按钮宽度 CGFloat itemW = self.bounds.size.width / 5; CGFloat itemH = self.bounds.size.height; for (UIView * subView in self.subviews) { if ([subView isKindOfClass:NSClassFromString(@"UITabBarButton")]) { // 设置宽度 subView.frame = CGRectMake(itemW * index, 0, itemW, itemH); index += 1; if (index == 2) { index += 1; } } }
相关文章推荐
- 新浪微博——点击按钮自动加关注代码
- WKWebView之OC代码注入,删除百度HTML页面的按钮
- 新浪微博“加关注”按钮代码
- 新浪微博——点击按钮自动加关注代码/一键关注
- 新浪微博加号按钮动画实现方案
- OC-UI-004.纯代码编写按钮的简单方法
- 新浪微博——点击按钮自动加关注代码
- 返回顶部按钮的代码jQuery topLink Plugin
- ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- 点击按钮复制网页代码
- C#-—通过代码建立按钮
- 黑马程序员------用代码创建按钮
- 使用Bootstrap美化按钮实例代码(demo)
- 让按钮失效5秒的js代码
- 动态创建按钮的JavaScript代码
- OC - UIStackView 的使用,纯代码方式
- 用C#代码画出一个Table同时增加 按钮事件为他动态增加行列
- js与oc间互相调用代码(含有部分支付统计分享)
- 判断textField为空时让按钮不可用的代码