2
0

LBXScanVideoZoomView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // LBXScanVideoZoomView.m
  3. // testSlider
  4. //
  5. // Created by csc on 16/3/19.
  6. // Copyright © 2016年 csc. All rights reserved.
  7. //
  8. #import "LBXScanVideoZoomView.h"
  9. @interface LBXScanVideoZoomView()
  10. @property (nonatomic, strong) UISlider *slider;
  11. @end
  12. @implementation LBXScanVideoZoomView
  13. // Only override drawRect: if you perform custom drawing.
  14. // An empty implementation adversely affects performance during animation.
  15. - (void)drawRect:(CGRect)rect
  16. {
  17. // Drawing code
  18. UIColor *colorLine = [UIColor whiteColor];
  19. CGColorRef color = colorLine.CGColor;
  20. CGContextRef ctx = UIGraphicsGetCurrentContext();
  21. CGContextSetStrokeColorWithColor(ctx, color);
  22. CGContextSetLineWidth(ctx, 2.0);
  23. CGFloat borderDiff = 20;
  24. CGFloat w = borderDiff/2;
  25. CGFloat diff = 5;
  26. //左边减号
  27. CGContextMoveToPoint(ctx, diff, CGRectGetHeight(self.frame)/2);
  28. CGContextAddLineToPoint(ctx, diff + w, CGRectGetHeight(self.frame)/2);
  29. //右边加号
  30. //横
  31. CGFloat rx = CGRectGetWidth(self.frame) - borderDiff + diff;
  32. CGContextMoveToPoint(ctx, rx, CGRectGetHeight(self.frame)/2);
  33. CGContextAddLineToPoint(ctx, rx + w, CGRectGetHeight(self.frame)/2);
  34. //竖
  35. CGFloat hDiff = CGRectGetHeight(self.frame)/2 - w/2;
  36. CGContextMoveToPoint(ctx, rx+w/2 , hDiff);
  37. CGContextAddLineToPoint(ctx, rx+w/2, CGRectGetHeight(self.frame)-hDiff);
  38. CGContextStrokePath(ctx);
  39. }
  40. - (UIImage *) toImage:(UIColor*)color size:(CGSize)size
  41. {
  42. CGRect rect=CGRectMake(0.0f, 0.0f, size.width, size.height);
  43. UIGraphicsBeginImageContext(rect.size);
  44. CGContextRef context = UIGraphicsGetCurrentContext();
  45. CGContextSetFillColorWithColor(context, [color CGColor]);
  46. CGContextFillRect(context, rect);
  47. UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
  48. UIGraphicsEndImageContext();
  49. return theImage;
  50. }
  51. - (id)initWithFrame:(CGRect)frame
  52. {
  53. if (self = [super initWithFrame:frame]) {
  54. }
  55. self.backgroundColor = [UIColor colorWithRed:10 green:10 blue:10 alpha:0.2];
  56. [self.slider setThumbImage:[self toImage:[UIColor whiteColor] size:CGSizeMake(3, 12)] forState:UIControlStateNormal];
  57. self.slider.minimumTrackTintColor = [UIColor whiteColor];
  58. self.slider.maximumTrackTintColor = [UIColor colorWithRed:146/255.0 green:146/255.0 blue:146/255.0 alpha:1.0];
  59. [self.slider addTarget:self action:@selector(sliderValueChange) forControlEvents:UIControlEventValueChanged];
  60. self.layer.masksToBounds = YES;
  61. self.layer.cornerRadius = 8.0;
  62. return self;
  63. }
  64. - (void)sliderValueChange
  65. {
  66. // NSLog(@"%f",self.slider.value);
  67. if (_block) {
  68. _block(self.slider.value);
  69. }
  70. }
  71. //- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
  72. - (UISlider*)slider
  73. {
  74. if (!_slider) {
  75. _slider = [[UISlider alloc]init];
  76. [self addSubview:_slider];
  77. _slider.minimumValue = 1.0;
  78. _slider.maximumValue = 50.0;
  79. }
  80. return _slider;
  81. }
  82. - (void)setMaximunValue:(CGFloat)value
  83. {
  84. self.slider.maximumValue = value;
  85. }
  86. - (void)layoutSubviews
  87. {
  88. [super layoutSubviews];
  89. CGFloat borderDiff = 20;
  90. _slider.bounds = CGRectMake(0, 0, CGRectGetWidth(self.frame)-borderDiff*2, CGRectGetHeight(self.frame));
  91. _slider.center = CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);
  92. }
  93. @end