简体   繁体   中英

Customized UISlider Minimum Track Image smaller than MaximumTrackImage

I am trying to create a UISlider with custom graphics but the issue i am facing is that the slider fill value is bigger in height than slider base value. Please see screen shot for this.

在此处输入图片说明

And how it should look like is as seen in picture below,

在此处输入图片说明

The code that i am using is pasted below,

[slider setThumbImage:[UIImage imageNamed:@"VolKnob"] forState:UIControlStateNormal];
[slider setMaximumTrackImage:[UIImage imageNamed:@"VolBase"] forState:UIControlStateNormal];
[slider setMinimumTrackImage:[UIImage imageNamed:@"VolFill"] forState:UIControlStateNormal];

You would need to make both images the same height, perhaps you can add transparency to the base or fill value so it appears to be smaller / bigger. I would also play with the CapInset to determine that right values for you. Do some research on the function resizableImageWithCapInsets:UIEdgeInsetsMake.

UIImage* minTrack = [UIImage imageNamed:@"VolFill"];
minTrack = [minTrack resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
[slider setMinimumTrackImage:minTrack forState:UIControlStateNormal];

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM