2

我正在尝试使用自定义图形创建 UISlider,但我面临的问题是滑块填充值的高度大于滑块基值。请参阅屏幕截图。

在此处输入图像描述

它应该是什么样子,如下图所示,

在此处输入图像描述

我正在使用的代码粘贴在下面,

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

1 回答 1

1

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.

于 2013-07-18T16:44:44.033 回答