// // ButtonContainerView.h // chemuchao // // Created by 遇见远洋 on 16/3/7. // Copyright © 2016年 zhaoxiaolu. All rights reserved. // #import <UIKit/UIKit.h> //按钮点击block typedef void(^spitlotBtnClick)(UIButton * btn); @interface ButtonContainerView : UIView @property (nonatomic,copy)spitlotBtnClick spitlotBlock;/**<<#展示对话内容的tableview#>*/ @end
//
// ButtonContainerView.m
// chemuchao
//
// Created by 遇见远洋 on 16/3/7.
// Copyright © 2016年 zhaoxiaolu. All rights reserved.
//
#import "ButtonContainerView.h"
#import "UIView+Extension.h"
//状态栏高度
#define kStateHeight 20
//总行数
#define kRows 2
//总列数
#define kCols 4
//九宫格个数
#define kCount 8
//九宫格之间的间隙
#define kMargin 5
//字体大小
#define kFont15 [UIFont systemFontOfSize:15]
@interface ButtonContainerView ()
@property (nonatomic,strong)NSMutableArray * btns;
@property (nonatomic,strong)NSArray * btnTitles;
@end
@implementation ButtonContainerView
- (NSMutableArray *)btns
{
if (!_btns) {
_btns = [NSMutableArray array];
}
return _btns;
}
-(NSArray *)btnTitles {
if (!_btnTitles) {
_btnTitles = @[@"堵成狗",@"堵成翔",@"路太窄",@"没灯",@"路不平",@"积水多",@"颠簸",@"路太脏"];
}
return _btnTitles;
}
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
- (void)setupUI {
for (int i = 0; i < kCount; i++) {
UIButton * btn = [[UIButton alloc]init];
[btn setTitle:self.btnTitles[i] forState:UIControlStateNormal];
[self addSubview:btn];
btn.layer.borderWidth = 1;
btn.layer.borderColor = [UIColor redColor].CGColor;
btn.titleLabel.font = [UIFont systemFontOfSize:13];
[btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(spitlotBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.btns addObject:btn];
}
}
-(void)layoutSubviews {
[super layoutSubviews];
[self.btns enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIButton * btn = obj;
btn.tag = idx;
//行号
NSUInteger row = idx/kCols;
//列号
NSUInteger col = idx%kCols;
CGFloat btnW = (self.width - kMargin*(kCols + 1))/kCols;
CGFloat btnH = (self.height - kMargin*(kRows + 1))/kRows -10;
CGFloat btnX = kMargin + col*(kMargin + btnW);
CGFloat btnY = kMargin + row*(kMargin + btnH) + kStateHeight;
btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
}];
}
#pragma mark 按钮点击事件
- (void)spitlotBtnClick:(UIButton *)sender {
NSAssert(self.spitlotBlock != nil, @"传入的block不能为空");
//执行block
self.spitlotBlock(sender);
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有