ios-小知识点-自定义uislider

//左右轨的图片
    UIImage *stetchLeftTrack= [UIImage imageNamed:@"brightness_bar.png"];
    UIImage *stetchRightTrack = [UIImage imageNamed:@"brightness_bar.png"];
    //滑块图片
    UIImage *thumbImage = [UIImage imageNamed:@"mark.png"];
    
    UISlider *sliderA=[[UISlider alloc]initWithFrame:CGRectMake(30, 320, 257, 7)];
    sliderA.backgroundColor = [UIColor clearColor];
    sliderA.value=1.0;
    sliderA.minimumValue=0.7;
    sliderA.maximumValue=1.0;
    
    [sliderA setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [sliderA setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
    //注意这里要加UIControlStateHightlighted的状态,否则当拖动滑块时滑块将变成原生的控件
    [sliderA setThumbImage:thumbImage forState:UIControlStateHighlighted];
    [sliderA setThumbImage:thumbImage forState:UIControlStateNormal];
    //滑块拖动时的事件
    [sliderA addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    //滑动拖动后的事件
    [sliderA addTarget:self action:@selector(sliderDragUp:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:sliderA];

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。