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
127
128
//
// LBXScanVideoZoomView.m
// testSlider
//
// Created by csc on 16/3/19.
// Copyright © 2016年 csc. All rights reserved.
//
#import "LBXScanVideoZoomView.h"
@interface LBXScanVideoZoomView()
@property (nonatomic, strong) UISlider *slider;
@end
@implementation LBXScanVideoZoomView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIColor *colorLine = [UIColor whiteColor];
CGColorRef color = colorLine.CGColor;
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ctx, color);
CGContextSetLineWidth(ctx, 2.0);
CGFloat borderDiff = 20;
CGFloat w = borderDiff/2;
CGFloat diff = 5;
//左边减号
CGContextMoveToPoint(ctx, diff, CGRectGetHeight(self.frame)/2);
CGContextAddLineToPoint(ctx, diff + w, CGRectGetHeight(self.frame)/2);
//右边加号
//横
CGFloat rx = CGRectGetWidth(self.frame) - borderDiff + diff;
CGContextMoveToPoint(ctx, rx, CGRectGetHeight(self.frame)/2);
CGContextAddLineToPoint(ctx, rx + w, CGRectGetHeight(self.frame)/2);
//竖
CGFloat hDiff = CGRectGetHeight(self.frame)/2 - w/2;
CGContextMoveToPoint(ctx, rx+w/2 , hDiff);
CGContextAddLineToPoint(ctx, rx+w/2, CGRectGetHeight(self.frame)-hDiff);
CGContextStrokePath(ctx);
}
- (UIImage *) toImage:(UIColor*)color size:(CGSize)size
{
CGRect rect=CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
}
self.backgroundColor = [UIColor colorWithRed:10 green:10 blue:10 alpha:0.2];
[self.slider setThumbImage:[self toImage:[UIColor whiteColor] size:CGSizeMake(3, 12)] forState:UIControlStateNormal];
self.slider.minimumTrackTintColor = [UIColor whiteColor];
self.slider.maximumTrackTintColor = [UIColor colorWithRed:146/255.0 green:146/255.0 blue:146/255.0 alpha:1.0];
[self.slider addTarget:self action:@selector(sliderValueChange) forControlEvents:UIControlEventValueChanged];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 8.0;
return self;
}
- (void)sliderValueChange
{
// NSLog(@"%f",self.slider.value);
if (_block) {
_block(self.slider.value);
}
}
//- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
- (UISlider*)slider
{
if (!_slider) {
_slider = [[UISlider alloc]init];
[self addSubview:_slider];
_slider.minimumValue = 1.0;
_slider.maximumValue = 50.0;
}
return _slider;
}
- (void)setMaximunValue:(CGFloat)value
{
self.slider.maximumValue = value;
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGFloat borderDiff = 20;
_slider.bounds = CGRectMake(0, 0, CGRectGetWidth(self.frame)-borderDiff*2, CGRectGetHeight(self.frame));
_slider.center = CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);
}
@end