GiGaMaskTime/GIGA/Modules/Mask/Exercises/View/GIGaQuestionSlider.m

118 lines
3.0 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// GIGaQuestionSlider.m
// GIGA
//
// Created by lianxiang on 2018/9/11.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GIGaQuestionSlider.h"
#import "UIColor+HexColor.h"
@interface GIGaQuestionSlider()
@end
@implementation GIGaQuestionSlider
- (instancetype)initWithFrame:(CGRect)frame type:(GIGaQuestionSliderType)type
{
self = [super initWithFrame:frame];
if (self) {
self.minimumValue = 0.0;
self.maximumValue = 1.0;
self.value = 0.5;
[self creatSubView:type];
}
return self;
}
-(void)creatSubView:(GIGaQuestionSliderType)type{
[self thumbimageView];
switch (type) {
case GIGaQuestionSliderTypeGray:
{
[self createUI];
}
break;
case GIGaQuestionSliderTypeGradient:
{
[self creatGradient];
}
break;
default:
break;
}
}
-(void)creatGradient{
self.minimumTrackTintColor=[UIColor clearColor];
self.maximumTrackTintColor=[UIColor clearColor];
NSArray *colorArr = @[(id)[[UIColor colorWithHex:0xFFFFFF] CGColor],
(id)[[UIColor colorWithHex:0xFFF3E4] CGColor],
(id)[[UIColor colorWithHex:0x9A9996] CGColor]];
NSArray *colorLocationArray = @[@0.0, @0.5, @1];
CAGradientLayer * gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.bounds;
gradientLayer.masksToBounds = YES;
gradientLayer.cornerRadius = self.frame.size.height /2 ;
gradientLayer.borderWidth = 1;
gradientLayer.borderColor =GIGARGB(215, 215, 215, 1).CGColor;
[gradientLayer setLocations:colorLocationArray];
[gradientLayer setColors:colorArr];
[gradientLayer setStartPoint:CGPointMake(0, 0)];
[gradientLayer setEndPoint:CGPointMake(1, 0)];
[self.layer addSublayer:gradientLayer];
}
-(void)createUI{
self.minimumValue = 0.0;
self.maximumValue = 1.0;
self.value = 0.5;
self.minimumTrackTintColor = GIGARGB(216,216, 216, 1);
self.maximumTrackTintColor = GIGARGB(216,216, 216, 1);
}
-(CGRect)trackRectForBounds:(CGRect)bounds
{
bounds.origin.x = bounds.origin.x;
bounds.origin.y = bounds.origin.y;
bounds.size.height = bounds.size.height;
bounds.size.width = bounds.size.width;
return bounds;
}
-(void)thumbimageView{
[self setThumbImage:[self OriginImage:[UIImage imageNamed:@"btn_slider_thumb"] scaleToSize:CGSizeMake(40, 40)] forState:UIControlStateNormal];
[self setThumbImage:[self OriginImage:[UIImage imageNamed:@"btn_slider_thumb"] scaleToSize:CGSizeMake(40, 40)] forState:UIControlStateHighlighted];
}
-(UIImage*) OriginImage:(UIImage*)image scaleToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);//size为CGSize类型即你所需要的图片尺寸
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@end