设置thumbImage并观察滑块消失?

发布于 2024-09-06 06:22:22 字数 486 浏览 3 评论 0原文

[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateHighlighted];
[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateNormal     ];

这会导致滑块图像消失吗?我的都没有了(拇指图像显示得很好。)

Apple 的文档听起来好像我可以使用上述 2 行代码中的任何一个。 (但我想我真的需要两者。)

而且我找不到任何关于“你必须始终做所有 4 件事”的内容:

Set the normal-state image.
Set the highlighted-state image.
Set the setMinimumTrackImage.
Set the setMaximumTrackImage.
[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateHighlighted];
[sld1 setThumbImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateNormal     ];

Would that cause the slider-bar image to disappear? Mine are all gone. (The thumb-image displays just fine.)

Apple's docs make it sounds like I can use any ONE of above 2 lines of code.
(But I guess I really need both.)

And I can't find anything about "you must always do all 4":

Set the normal-state image.
Set the highlighted-state image.
Set the setMinimumTrackImage.
Set the setMaximumTrackImage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ペ泪落弦音 2024-09-13 06:22:22

如果您开始使用图形自定义 UISlider,则必须设置至少 3 个图形。
轨迹栏的右侧和左侧以及拇指图像:

这是我上次使用 UISlider 时的做法:

    CGRect frame = CGRectMake(20.0f, 6.0, 280.0f, 20.0f);
    UISlider *customSlider = [[UISlider alloc] initWithFrame:frame];
    [customSlider addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
    [customSlider addTarget:self action:@selector(sliderStart:) forControlEvents:UIControlEventTouchDown];
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpInside];        
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpOutside];   

    // in case the parent view draws with a custom color or gradient, use a transparent color
    customSlider.backgroundColor = [UIColor clearColor];    
    UIImage *stetchLeftTrack = [[UIImage imageNamed:@"slider.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

     UIImage *stetchRightTrack = [[UIImage imageNamed:@"slider_right.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

    [customSlider setThumbImage: [UIImage imageNamed:@"slider-knop.png"] forState:UIControlStateNormal];
    [customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

就我的光学而言,UISlider 的突出显示状态或任何其他状态(您的手指)没有意义可能会覆盖拇指图像,因此用户永远不会看到它。
我不确定它只是从 UIButton 扩展而来,也许它无法处理它?

If you start out customizing the UISlider with graphics, you must set at least 3 pieces of graphics.
Right and left side of the trackbar and the thumb image:

Here is how I did it the last time I used the UISlider:

    CGRect frame = CGRectMake(20.0f, 6.0, 280.0f, 20.0f);
    UISlider *customSlider = [[UISlider alloc] initWithFrame:frame];
    [customSlider addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
    [customSlider addTarget:self action:@selector(sliderStart:) forControlEvents:UIControlEventTouchDown];
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpInside];        
    [customSlider addTarget:self action:@selector(sliderEnd:) forControlEvents:UIControlEventTouchUpOutside];   

    // in case the parent view draws with a custom color or gradient, use a transparent color
    customSlider.backgroundColor = [UIColor clearColor];    
    UIImage *stetchLeftTrack = [[UIImage imageNamed:@"slider.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

     UIImage *stetchRightTrack = [[UIImage imageNamed:@"slider_right.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

    [customSlider setThumbImage: [UIImage imageNamed:@"slider-knop.png"] forState:UIControlStateNormal];
    [customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

I my optics it does not make sense to have a highlighted state for the UISlider, or any other state, your finger will likely cover the thumb image, so the user will never see it.
I am not sure it just extends from UIButton and maybe it can't handle it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文