UISlider

来源:互联网 发布:明底线知敬畏演讲稿 编辑:程序博客网 时间:2024/06/02 23:17
#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 

0 0
原创粉丝点击