#import "ViewController.h"
@interface ViewController ()
{
UISlider * slider;
UIView *view;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
slider = [[UISlider alloc] initWithFrame:CGRectMake(10,50,300,30)];
[self.view addSubview:slider];
[slider addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];
slider.minimumValue=0;
slider.maximumValue=1000;
slider.minimumValueImage = [UIImage imageNamed:@"dp.jpg"];
slider.maximumValueImage = [UIImage imageNamed:@"dp.jpg"];
//slider.continuous = NO;
slider.minimumTrackTintColor = [UIColor redColor];
slider.maximumTrackTintColor = [UIColor greenColor];
slider.thumbTintColor = [UIColor blueColor];
view = [[UIView alloc] initWithFrame:CGRectMake(10,300,50,50)];
view.backgroundColor = [UIColor orangeColor];
[self.view addSubview: view];
}
- (void) action:(UISlider *)slider{
//NSLog(@"%f",slider.value);
view.frame = CGRectMake(slider.value/1000*250,300,50,50);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[slider setValue:arc4random()%1000 animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
UISlider
最新推荐文章于 2022-02-13 14:06:11 发布