//
// ViewController.m
// UISlider
//
// Created by City--Online on 15/5/19.
// Copyright (c) 2015年 XQB. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong) UISlider *slider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_slider=[[UISlider alloc]initWithFrame:CGRectMake(10, 100, 200, 50)];
_slider.minimumValue=0;
_slider.maximumValue=100;
_slider.value=30;
//设置滑杆、滑块、轨道的颜色 同理可以设置图片 其他属性方法基本差不多 不再写
_slider.minimumTrackTintColor=[UIColor redColor];
_slider.maximumTrackTintColor=[UIColor blueColor];
_slider.thumbTintColor=[UIColor yellowColor];
//设置只有在离开滑动条的最后时刻才触发滑动事件
_slider.continuous=NO;
[_slider addTarget:self action:@selector(valuechanged) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_slider];
}
-(void)valuechanged
{
NSLog(@"%f",_slider.value);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
时间: 2024-11-10 11:53:15