UISlider 滑杆 开发笔记

    slider = [[UISlideralloc]initWithFrame:CGRectMake(20,250, 300,10)];

   

    [slideraddTarget:selfaction:@selector(sliderChange:)forControlEvents:UIControlEventValueChanged];

    


    //最大值

   slider.maximumValue =100;

    //最小值

   slider.minimumValue =0;

    

    //设置滑杆的值

 //  [slider setValue:10 animated:YES];

    //最小值左旁边显示一张图片

    slider.minimumValueImage =[UIImageimageNamed:@"itemImage.png"];

    

    //最大值左旁边显示一张图片

    slider.maximumValueImage =[UIImageimageNamed:@"itemImage.png"];

    

    //默认为yes  设置No 不能获取滑动的值,只能获取最大值和最小值

    //if set, value change events are generated any time the value changes due to dragging.

    slider.continuous =YES;

    

    //从最小值滑向最大值时杆的颜色

    slider.minimumTrackTintColor = [UIColorredColor];

    

    //从最大值滑向最小值时杆的颜色

    slider.maximumTrackTintColor = [UIColorblueColor];

    

    //The color used to tint the standard thumb images.

    slider.thumbTintColor = [UIColorblackColor];

    

    

    //在滑块圆按钮添加图片

    [slidersetThumbImage:[UIImage imageNamed:@"slider.png"]forState:UIControlStateNormal];

    

    

    //改变背景样式

    //从最大值滑向最小值时杆背景图片

    [slidersetMaximumTrackImage:[UIImage imageNamed:@"test3.png"]forState:UIControlStateNormal];

    

    //从最小值滑向最大值时杆背景图片

    [slidersetMinimumTrackImage:[UIImage imageNamed:@"itemImage.png"]forState:UIControlStateNormal];


    // lets a subclass lay out the track and thumb as needed

//    - (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;

//    - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds;

//    - (CGRect)trackRectForBounds:(CGRect)bounds;

//    - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;

    

    

    

 

    



-(void)sliderChange:(id)sender

{

    UISlider *sliderSender = (UISlider *)sender;

    //滑动取得的值

    int progressAsint = (int)round(sliderSender.value);

    

    NSLog(@"progressAsint = %d",progressAsint);

}

你可能感兴趣的:(控件)