UISlider

强保臣
2023-12-01
<span style="font-size:18px;">//
//  RootView.m
//  UILession6-slider
//
//  Created by lanou3g on 15/8/30.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootView.h"


@implementation RootView
-(void)dealloc{
    [_slider release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self addView];
    }
    return self;
}

-(void)addView{
    
    //初始化一个slider
    _slider = [[UISlider alloc]initWithFrame:CGRectMake(40, 300, 300, 40)];
    
    //1.设置滑块的最小值
    _slider.minimumValue = 0;
//    NSLog(@"%f",_slider.value);
    
    //2.设置滑块的最大值
    _slider.maximumValue = 100;

    //3.continuous:若continuous设置为YES,在拖动滑块的任何时候,滑块的值都会改变.其默认值为YES;当continuous设置为NO时,在滑块jieshu时才获取滑块的值.
    _slider.continuous = NO;
    
    //4.minimumValueImage:在滑块条最小值处设置的图片,默认为nil
//    _slider.minimumValueImage = [UIImage imageNamed:@"blc@2x"];
    
    //5.maximumValueImage:在滑块条最大值处设置的图片,默认为nil
//    _slider.maximumValueImage = [UIImage imageNamed:@"blc@2x"];
    
    //6.minimumTrackTintColor:设置滑块左侧的颜色
    _slider.minimumTrackTintColor = [UIColor redColor];
    
    //7.设置滑块右侧的颜色
    _slider.maximumTrackTintColor = [UIColor blackColor];
    
    //8.设置滑块的背景图片,但是要加上图片的格式转换
    //setThumbImage:(UIImage *)image forState:(UIControlState)state:设置滑块的背景图片
    //imageWithRenderingMode:(UIImageRenderingMode)renderingMode:图片的格式转换
//    [_slider setThumbImage:[[UIImage imageNamed:@"blc@2x" ]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    //9.thumbTintColor:设置滑块的颜色,但是要在之前给滑块加上图片否则,滑块的颜色显示不出来.
    _slider.thumbTintColor = [UIColor greenColor];
    
    //10.setMinimumTrackImage:(UIImage *)image forState:(UIControlState)state :给滑块左(下)侧的进度条添加图片
//    [_slider setMinimumTrackImage:[[UIImage imageNamed:@"blc@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    //11.setMaximumTrackImage:(UIImage *)image forState:(UIControlState)state   :给滑块右(上)侧的进度条添加图片

   [ _slider setMaximumTrackImage:[[UIImage imageNamed:@"blc@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    //12.给slider添加响应事件
    [_slider addTarget:self action:@selector(sliderA) forControlEvents:UIControlEventValueChanged];
    
    //以下为UISlider的只读属性
//    13.currentMaximumTrackImage : 滑块条最大值处设置的图片
//    14.currentMinimumTrackImage : 滑块条最小值处设置的图片
//    15.currentThumbImage: 当前滑块的图片
    
    
    [self addSubview:_slider];
    
    
}

-(void)sliderA{
    NSLog(@"%f",_slider.value);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
</span>

 类似资料:

相关阅读

相关文章

相关问答