本文主要是介绍iOS UISlider简单使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//我把View封装到了RootView,在viewController里初始化RootView *rootV = [[RootView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];[self.view addSubview:rootV];[rootV release];
在封装起来的View里
//初始化
- (instancetype)initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];if (self) {[self create];}return self;
}- (void)create{UISlider *sliR = [[UISlider alloc] initWithFrame:CGRectMake((375 - 200) / 2, 500, 200, 30)];//slider最大值sliR.maximumValue = 256;//slider最小值sliR.minimumValue = 0;//设置最小进度值颜色 滑块左侧进度条颜色
// sliR.minimumTrackTintColor = [UIColor redColor];//设置最大进度值颜色 滑块左侧进度条颜色
// sliR.maximumTrackTintColor = [UIColor blackColor];//添加滑块背景图片
// [sliR setThumbImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];//slider执行方法[sliR addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];sliR.tag = 1000;[self addSubview:sliR];UISlider *sliG = [[UISlider alloc] initWithFrame:CGRectMake((375 - 200) / 2, 550, 200, 30)];sliG.maximumValue = 256;sliG.minimumValue = 0;[sliG addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];sliG.tag = 1001;[self addSubview:sliG];UISlider *sliB = [[UISlider alloc] initWithFrame:CGRectMake((375 - 200) / 2, 600, 200, 30)];sliB.maximumValue = 256;sliB.minimumValue = 0;[sliB addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];sliB.tag = 1002;[self addSubview:sliB];}- (void)action:(UISlider *)sli{UISlider *sliR = (UISlider *)[self viewWithTag:1000];UISlider *sliG = (UISlider *)[self viewWithTag:1001];UISlider *sliB = (UISlider *)[self viewWithTag:1002];self.backgroundColor = [UIColor colorWithRed:sliR.value / 255.0 green:sliG.value / 255.0 blue:sliB.value / 255.0 alpha:1];
}
这篇关于iOS UISlider简单使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!