#import "MineTuChaoViewController.h"
#import "ChoosePhotosview.h"
@interface MineTuChaoViewController ()<UIScrollViewDelegate>
{
CGFloat _btnWidth,_btnHeight;
NSInteger _chooseBtnNum; //-1 为初始化未选中, 其他为当前按钮事件
}
@property(nonatomic,strong) UIButton *rightBtn;
@property(nonatomic,strong) ChoosePhotosview *photoView;
@property(nonatomic,strong) UIScrollView *scrollView;
@property(nonatomic,strong) UIView *contentView;
@property(nonatomic,strong) UIView *leiXingBkgV, *miaoShuBkgV, *zhaopianBkgV;
@property(nonatomic,strong) NSMutableArray *arrBtn;
@property(nonatomic,strong) NSMutableArray *arrLeiXing;
@end
@implementation MineTuChaoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"我要吐槽";
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.leftBarButtonItem = [BackButtonItem getBackItemWithTitle:@"" image:[UIImage imageNamed:@"fl_fanhui-jian"] target:self action:@selector(goBackPage:)];
//右侧确认按钮
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn.userInteractionEnabled = YES;
[self.rightBtn setTitle:@"提交" forState:UIControlStateNormal];
self.rightBtn.titleLabel.font = MIDDLE_LIT_FONT;
[self.rightBtn setTitleColor:THEME_GREEN_COLOR forState:UIControlStateNormal];
[self.rightBtn addTarget:self action:@selector(clickedRightBtn:) forControlEvents:UIControlEventTouchUpInside];
self.rightBtn.frame = CGRectMake(0, 0, 40, 30) ;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightBtn];
[self getData];
[self drawScrollview];
}
-(void)getData{
_chooseBtnNum = -1;
self.arrLeiXing = [@[@"商品质量",@"售后服务",@"物流",@"APP优化",@"业务运营",@"其他"] mutableCopy];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.translucent = NO;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
}
-(void)drawScrollview{
[self.scrollView removeFromSuperview];
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)] ;
self.scrollView.userInteractionEnabled = YES;
self.scrollView.delegate = self;
self.scrollView.bounces = YES;
self.scrollView.backgroundColor = BKG_HEX_GRAY_EEE;
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.scrollView layoutIfNeeded];
self.contentView = [[UIView alloc]init];
[self.scrollView addSubview:self.contentView];
self.contentView.userInteractionEnabled = YES;
self.contentView.backgroundColor = BKG_HEX_GRAY_EEE;
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.scrollView);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(100);
}];
[self.contentView layoutIfNeeded];
_btnWidth = (SCREEN_WIDTH-4*TEXT_EDGE_DISTANCE)/3;
_btnHeight = 32;
//问题类型
[self drawWenTiView];
//问题描述
[self drawMiaoShuView];
//照片
[self drawZhaoPian];
}
-(void)showChooosePhotoV{
[self.photoView removeFromSuperview];
self.photoView = [[ChoosePhotosview alloc]init];
self.photoView.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.7];
[self.view addSubview:self.photoView];
__weak typeof(self)weakSelf = self;
[UIView animateWithDuration:0.2 animations:^{
[weakSelf.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
} completion:^(BOOL finished) {
}];
}
//类型
-(void)drawWenTiView{
self.leiXingBkgV = [[UIView alloc]init];
self.leiXingBkgV.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.leiXingBkgV];
[self.leiXingBkgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView.mas_centerX);
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.height.mas_equalTo(80);
}];
UIView *shangV = [[UIView alloc]init];
[self.leiXingBkgV addSubview:shangV];
shangV.backgroundColor = [UIColor whiteColor];
[shangV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self.leiXingBkgV);
make.height.mas_equalTo(34);
}];
UIView *line_b = [[UIView alloc]init];
[shangV addSubview:line_b];
line_b.userInteractionEnabled = YES;
line_b.backgroundColor = BKG_HEX_GRAY_E5;
[line_b mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(shangV);
make.height.mas_equalTo(0.5);
}];
UILabel *nameL = [[UILabel alloc]init];
[shangV addSubview:nameL];
nameL.text = @"问题类型";
nameL.font = MIDDLE_LIT_FONT;
nameL.textColor = TEXT_HEX_MID_GRAY;
[nameL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(shangV.mas_centerY);
make.left.mas_equalTo(shangV.mas_left).mas_offset(TEXT_EDGE_DISTANCE);
make.width.mas_greaterThanOrEqualTo(30);
}];
[nameL setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
UILabel *nxingL = [[UILabel alloc]init];
[shangV addSubview:nxingL];
nxingL.text = @"*";
nxingL.font = MIDDLE_LIT_FONT;
nxingL.textColor = TEXT_HEX_RED_f95a;
[nxingL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(nameL.mas_top);
make.left.mas_equalTo(nameL.mas_right);
}];
[nxingL setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
for (int i = 0 ; i<self.arrLeiXing.count; i++) {
NSString *str = self.arrLeiXing[i];
UIButton *b_tn = [UIButton buttonWithType:UIButtonTypeSystem];
[self.leiXingBkgV addSubview:b_tn];
[b_tn setTitle:str forState:UIControlStateNormal];
b_tn.titleLabel.font = MIDDLE_LIT_FONT;
[b_tn setTitleColor:TEXT_HEX_MID_GRAY forState:UIControlStateNormal];
b_tn.layer.borderColor = BKG_HEX_GRAY_C9.CGColor;
b_tn.layer.borderWidth = 1;
b_tn.tag = 1000+i;
[self.arrBtn addObject:b_tn];
[b_tn addTarget:self action:@selector(clickedWenTiLeiXingBtn:) forControlEvents:UIControlEventTouchUpInside];
[b_tn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(shangV.mas_bottom).mas_offset((i/3)*(TEXT_EDGE_DISTANCE+_btnHeight)+TEXT_EDGE_DISTANCE);
make.left.mas_equalTo(self.leiXingBkgV.mas_left).mas_offset((i%3)*(_btnWidth+TEXT_EDGE_DISTANCE)+TEXT_EDGE_DISTANCE);
make.size.mas_equalTo(CGSizeMake(_btnWidth, _btnHeight));
}];
[b_tn layoutIfNeeded];
[self.leiXingBkgV mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView.mas_centerX);
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.bottom.mas_equalTo(b_tn.mas_bottom).mas_offset(TEXT_EDGE_DISTANCE);
}];
}
}
//问题描述
-(void)drawMiaoShuView{
self.miaoShuBkgV = [[UIView alloc]init];
self.miaoShuBkgV.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.miaoShuBkgV];
[self.miaoShuBkgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView.mas_centerX);
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.leiXingBkgV.mas_bottom).mas_offset(TEXT_EDGE_DISTANCE);
make.height.mas_equalTo(80);
}];
UIView *shangV = [[UIView alloc]init];
[self.leiXingBkgV addSubview:shangV];
shangV.backgroundColor = [UIColor whiteColor];
[shangV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self.leiXingBkgV);
make.height.mas_equalTo(34);
}];
UIView *line_b = [[UIView alloc]init];
[shangV addSubview:line_b];
line_b.userInteractionEnabled = YES;
line_b.backgroundColor = BKG_HEX_GRAY_E5;
[line_b mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(shangV);
make.height.mas_equalTo(0.5);
}];
UILabel *nameL = [[UILabel alloc]init];
[shangV addSubview:nameL];
nameL.text = @"问题类型";
nameL.font = MIDDLE_LIT_FONT;
nameL.textColor = TEXT_HEX_MID_GRAY;
[nameL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(shangV.mas_centerY);
make.left.mas_equalTo(shangV.mas_left).mas_offset(TEXT_EDGE_DISTANCE);
make.width.mas_greaterThanOrEqualTo(30);
}];
[nameL setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
UILabel *nxingL = [[UILabel alloc]init];
[shangV addSubview:nxingL];
nxingL.text = @"*";
nxingL.font = MIDDLE_LIT_FONT;
nxingL.textColor = TEXT_HEX_RED_f95a;
[nxingL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(nameL.mas_top);
make.left.mas_equalTo(nameL.mas_right);
}];
[nxingL setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
//照片
-(void)drawZhaoPian{
}
#pragma mark -- clickedWenTiLeiXingBtn 问题类型 --
-(void)clickedWenTiLeiXingBtn:(UIButton *)sender{
NSInteger num = sender.tag-1000;
if (_chooseBtnNum == num) {
for (int i = 0; i<self.arrBtn.count; i++) {
UIButton *btn = self.arrBtn[i];
[btn setTitleColor:TEXT_HEX_MID_GRAY forState:UIControlStateNormal];
btn.layer.borderColor = BKG_HEX_GRAY_C9.CGColor;
}
// 取消选择
_chooseBtnNum=-1;
} else {
_chooseBtnNum = num;
for (int i = 0; i<self.arrBtn.count; i++) {
UIButton *btn = self.arrBtn[i];
if (i == num) {
[btn setTitleColor:TEXT_RED_ORANGE forState:UIControlStateNormal];
btn.layer.borderColor = TEXT_RED_ORANGE.CGColor;
} else {
[btn setTitleColor:TEXT_HEX_MID_GRAY forState:UIControlStateNormal];
btn.layer.borderColor = BKG_HEX_GRAY_C9.CGColor;
}
}
}
NSLog(@"num %ld",num);
}
#pragma mark -- clickedRightBtn 右键 --
-(void)clickedRightBtn:(UIButton *)sender{
[self showChooosePhotoV];
}
#pragma mark -- goBackPage 返回 --
-(void)goBackPage:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSMutableArray *)arrLeiXing{
if (!_arrLeiXing) {
_arrLeiXing = [NSMutableArray array];
}
return _arrLeiXing;
}
-(NSMutableArray *)arrBtn{
if (!_arrBtn) {
_arrBtn = [NSMutableArray array];
}
return _arrBtn;
}