//
//  ERTCBeautySliderView.m
//  ERTCDemo
//
//  Created by wangjinlong23 on 2022/8/16.
//

#import "ERTCBeautySliderView.h"

@interface ERTCBeautySliderView ()

@property (nonatomic, strong) UIImageView *valueTipImageView;
@property (nonatomic, strong) UILabel *valueTipLabel;

@end

@implementation ERTCBeautySliderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame])
    {
        UIImage *image = [UIImage  imageNamed:@"img_dot_26x26"];
        [self setThumbImage:image forState:UIControlStateNormal];
        
        //小于滑块当前值滑块条的颜色，默认为蓝色
        self.minimumTrackTintColor = [UIColor colorWithRed:(0x3E/255.f) green:(0x80/255.f) blue:(0xFF/255.f) alpha:1];
        //大于滑块当前值滑块条的颜色，默认为白色
        self.maximumTrackTintColor = [UIColor whiteColor];
        
        [self addTarget:self action:@selector(sliderDidEndSliding:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchUpInside];
    }

    return self;
}

-(CGRect)trackRectForBounds:(CGRect)bounds {
    bounds.size.height = 6;
    return bounds;
}

/// 设置 value
- (void)setValue:(float)value animated:(BOOL)animated {
    [super setValue:value animated:animated];
//    NSLog(@"BeautySliderView setValue:%f tracking:%d", value, self.tracking);
    self.tipImageView.hidden = !self.tracking;
}

#pragma mark - Slider值变化添加响应方法
/// Slider值变化添加响应方法
/// @param slider UISlider对象
- (void)sliderDidEndSliding:(UISlider *)slider {
    NSLog(@"BeautySliderView sliderDidEndSliding value:%f", slider.value);
    self.tipImageView.hidden = YES;
}

-(void)dealloc {
    NSLog(@"ERTCBeautySliderView dealloc");
}
@end
