gpt4 book ai didi

ios - 具有自定义轨道图像/颜色的水平和垂直滑动条

转载 作者:行者123 更新时间:2023-11-29 03:39:09 49 4
gpt4 key购买 nike

如何使用 xib 创建具有自定义轨道图像/颜色的水平和垂直滑动条?

目前我已经使用了 xib 的水平滑动条,现在我需要像上面所述的那样对其进行自定义。

当前使用此代码使我的 UISlider 以垂直位置显示:

CGAffineTransform sliderRotation = CGAffineTransformIdentity;
sliderRotation = CGAffineTransformRotate(sliderRotation, -(M_PI / 2));
customSliderVertical.transform = sliderRotation;

最佳答案

最终经过一些努力和时间找到了有助于获得所需输出的解决方案,我得到了带有以下代码的垂直和水平 UISlider:

/////////////Vertical Slider/////////////
[customSliderVertical addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSliderVertical.backgroundColor = [UIColor clearColor];
customSliderVertical.opaque = 20.0;
UIImage *stretchUpTrack = [[UIImage imageNamed:@"color.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
UIImage *stretchDownTrack = [[UIImage imageNamed:@"color2.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
[customSliderVertical setThumbImage:[UIImage imageNamed:@"rounded.png"]forState:UIControlStateNormal];
[customSliderVertical setMinimumTrackImage:stretchUpTrack forState:UIControlStateNormal];
[customSliderVertical setMaximumTrackImage:stretchDownTrack forState:UIControlStateNormal];
customSliderVertical.minimumValue = 0.0;
customSliderVertical.maximumValue = 100.0;
customSliderVertical.continuous = NO;
customSliderVertical.value = 50.0;
CGAffineTransform sliderRotation = CGAffineTransformIdentity;
sliderRotation = CGAffineTransformRotate(sliderRotation, -(M_PI / 2));
customSliderVertical.transform = sliderRotation;

/////////////Horizontal Slider/////////////
[customSliderHorizontal addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSliderHorizontal.backgroundColor = [UIColor clearColor];
customSliderHorizontal.opaque = 20.0;
UIImage *stretchLeftTrack2 = [[UIImage imageNamed:@"color.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
UIImage *stretchRightTrack2 = [[UIImage imageNamed:@"color2.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
[customSliderHorizontal setThumbImage:[UIImage imageNamed:@"rounded.png"]forState:UIControlStateNormal];
[customSliderHorizontal setMinimumTrackImage:stretchLeftTrack2 forState:UIControlStateNormal];
[customSliderHorizontal setMaximumTrackImage:stretchRightTrack2 forState:UIControlStateNormal];
customSliderHorizontal.minimumValue = 0.0;
customSliderHorizontal.maximumValue = 100.0;
customSliderHorizontal.continuous = NO;
customSliderHorizontal.value = 50.0;

关于ios - 具有自定义轨道图像/颜色的水平和垂直滑动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18697897/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com