开发者

problem with UISlider : printing values of the slider and getting to change the style

开发者 https://www.devze.com 2023-03-10 03:04 出处:网络
I am facing some problem with UISlider progra开发者_StackOverflow社区mming. 1) style: I know we have to set the minimum and maximum images. I am just not sure what images and any image reference wil

I am facing some problem with UISlider progra开发者_StackOverflow社区mming.

1) style: I know we have to set the minimum and maximum images. I am just not sure what images and any image reference will be great ? I only want to change from blue to black !

2) also, my code for the UISlider is this :

in header file:

UISlider *slider;

in code file:

 //slider
 CGRect frame=CGRectMake(10, 70, 300, 10);
 photoSlider=[[UISlider alloc] initWithFrame:frame];
 photoSlider.minimumValue=0.0;
 photoSlider.maximumValue=90.0; //maximumPhotoImage
 photoSlider.continuous=NO;
 photoSlider.value=10.0;
 photoSlider.backgroundColor=[UIColor clearColor];
 //photoSlider

 [photoSlider addTarget:self action:@selector(updateImage:)   forControlEvents:UIControlEventValueChanged];
 [self.view addSubview:photoSlider];

- (void) updateImage:(id) sender  
{
   NSLog(@"val: %d",photoSlider.value);
}

The values that I get from the function are 0 at both ends and very large value in between (both positive and negative...random values).

Can anyone kindly help me out ? Thanks.


For part 1, to replace the default blue part of the slider track with black, you could take a snapshot of the default blue track and convert it to a darker grayscale like this (only need the left end and 1 pixel of the stretchable part):

problem with UISlider : printing values of the slider and getting to change the style


and call setMinimumTrackImage:forState::

UIImage *minTrackImg = [[UIImage imageNamed:@"MinimumTrackImage.png"] 
    stretchableImageWithLeftCapWidth:4 topCapHeight:0];
[photoSlider setMinimumTrackImage:minTrackImg forState:UIControlStateNormal];


For part 2, the values logged don't make sense because the value property is of type float and you need to use %f instead of %d (see String Format Specifiers):

NSLog(@"val: %f",photoSlider.value);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号