12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- //
- // ComprehensiveView.m
- // YouHuiProject
- //
- // Created by liuxueli on 2019/1/4.
- // Copyright © 2019 kuxuan. All rights reserved.
- //
- #import "ComprehensiveView.h"
- @implementation ComprehensiveView
- -(instancetype)initWithFrame:(CGRect)frame CompreensiveArray:(NSArray *)arr
- {
- self =[super initWithFrame:frame];
- if (self) {
- self.backgroundColor =[UIColor whiteColor];
- [self initSubViews:arr];
- }
- return self;
- }
- -(void)initSubViews:(NSArray *)array
- {
- self.btnArray =[NSMutableArray array];
- for (int i =0; i<array.count; i++) {
- NSDictionary *dics =array[i];
- UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(0, i*40,SCREEN_WIDTH, 39.5)];
- [button setTitle:dics[@"title"] forState:UIControlStateNormal];
- [button setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
- button.titleLabel.font =[UIFont systemFontOfSize:13];
- [self addSubview:button];
- button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
- button.titleEdgeInsets=UIEdgeInsetsMake(0, 34, 0, 0);
- button.tag = [dics[@"type"] integerValue]*100;
- [button addTarget:self action:@selector(selectSortType:) forControlEvents:UIControlEventTouchUpInside];
-
- if (self.selectDic.allKeys == 0) {
- if (i == 0) {
- [button setTitleColor:[UIColor YHColorWithHex:0xFF5A4A] forState:UIControlStateNormal];
- self.selectDic = dics;
-
- UIImageView *rightImg =[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-45, 15, 13, 8)];
- rightImg.tag =1254;
- [rightImg setImage:[UIImage imageNamed:@"duihao-2"]];
- [self addSubview:rightImg];
- }
- }
-
-
- [self.btnArray addObject:button];
-
- UIView *lineviw =[[UIView alloc]initWithFrame:CGRectMake(0, i*40+39.5, SCREEN_WIDTH, 0.5)];
- lineviw.backgroundColor =[UIColor lineColor];
- [self addSubview:lineviw];
-
- }
- }
- -(void)setSelectDic:(NSDictionary *)selectDic
- {
- _selectDic = selectDic;
- UIImageView *imgv =[self viewWithTag:1254];
- for (int i =0; i<self.btnArray.count; i++) {
- UIButton *button =self.btnArray[i];
- if ([selectDic[@"type"] integerValue] == button.tag/100) {
- [button setTitleColor:[UIColor YHColorWithHex:0xFF5A4A] forState:UIControlStateNormal];
- imgv.frame=CGRectMake(SCREEN_WIDTH-45, 15+i*40, 13, 8);
-
- }else{
- [button setTitleColor:[UIColor YHColorWithHex:0x666666] forState:UIControlStateNormal];
- }
-
- }
-
- }
- -(void)selectSortType:(UIButton *)btn
- {
- if ([self.delegate respondsToSelector:@selector(selectWithBtn:)]) {
- [self.delegate selectWithBtn:btn];
- }
- }
- @end
|