UISlider

<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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值