DWBottomView.m 3.04 KB
Newer Older
Han Ruisong's avatar
Han Ruisong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
//  DWBottomView.m
//  Demo
//
//  Created by luyang on 2017/11/9.
//  Copyright © 2017年 com.bokecc.www. All rights reserved.
//

#import "DWBottomView.h"

@interface DWBottomView()

@end


@implementation DWBottomView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self =[super initWithFrame:frame];
    
    if (self) {
      
        
        _height =frame.size.height;
        _width =frame.size.width;
        [self loadSubviews];
    }
    
    return self;
    
}

- (void)loadSubviews{
    
    _videoBtn =[self creatButtonWithTitle:@"视频播放" selector:@selector(videoPlay:) frame:CGRectMake((_width/2-53)/2, 13,53, 13)];
    _videoBtn.selected =YES;
    
    _audioBtn =[self creatButtonWithTitle:@"音频播放" selector:@selector(audioPlay:) frame:CGRectMake((_width/2-53)/2+_width/2, 13,53, 13)];
    
    _verticalView =[[UIView alloc]initWithFrame:CGRectMake((_width -1)/2, 10, 0.5, 19)];
    _verticalView.backgroundColor =[DWTools colorWithHexString:@"#ffffff"];
    _verticalView.alpha =0.3;
    [self addSubview:_verticalView];
    
    _horizontallyView =[[UIView alloc]init];
    _horizontallyView.backgroundColor =[DWTools colorWithHexString:@"#ffffff"];
  //  _horizontallyView.alpha =0.4;
    [self addSubview:_horizontallyView];
    [_horizontallyView mas_remakeConstraints:^(MASConstraintMaker *make) {
      
        make.top.mas_equalTo(_videoBtn.mas_bottom).offset(4.5);
        make.left.right.mas_equalTo(_videoBtn);
        make.height.mas_equalTo(1);
        
    }];
    
    
    
}



- (void)videoPlay:(UIButton *)sender{
    
    _audioBtn.selected =NO;
    _videoBtn.selected =YES;
    
    [self remakeConstraints:sender];
    
    if (_delegate && [_delegate respondsToSelector:@selector(videoBottomViewPlayAction)]) {
        
        [_delegate videoBottomViewPlayAction];
        
    }
}



- (void)audioPlay:(UIButton *)sender{
    
    _audioBtn.selected =YES;
    _videoBtn.selected =NO;
    
    [self remakeConstraints:sender];
    
    if (_delegate && [_delegate respondsToSelector:@selector(audioBottomViewPlayAction)]) {
        
        [_delegate audioBottomViewPlayAction];
        
    }
    
    
}

- (void)remakeConstraints:(UIButton *)sender{
    
    [_horizontallyView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(sender.mas_bottom).offset(4.5);
        make.left.right.mas_equalTo(sender);
        make.height.mas_equalTo(1);
        
    }];
    
    
}

- (UIButton *)creatButtonWithTitle:(NSString *)title selector:(SEL )selector frame:(CGRect )frame{
    
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font =[UIFont systemFontOfSize:12];
  //  btn.alpha =0.5;
    btn.frame =frame;
    [self addSubview:btn];
    
    return btn;
    
}


@end