更改iPhone UISlider条形图 [英] Change iPhone UISlider bar image

查看:93
本文介绍了更改iPhone UISlider条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用了 UISlider ,但我想使用自定义的外观。我已经将拇指改为我自己的形象,但有没有办法改变吧?我有一个我想要使用的条形图像,但看不到如何做到这一点。

I'm using a UISlider in my app but I'd like to use a custom "look-and-feel" for it. I have changed the thumb to my own image but is there a way to change the bar also? I have a bar image I would like to use but can't see how to do this.

我找到了如何更改最大和最小图像而不是条形图本身。

I have found how to change the max and min image but not the bar itself.

推荐答案

你是正确的使用 -setMinimumTrackImage:forState: -setMaximumTrackImage:forState:方法。你错过的是你应该向他们提供可伸缩的 UIImage ,剩下的就是自动处理:

You were right to use -setMinimumTrackImage:forState: and -setMaximumTrackImage:forState: methods. What you missed is that you should provide stretchable UIImage to them, the rest is taken care of automagically:

UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"SliderMin.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"SliderMax.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];
[mySlider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];
[mySlider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal];

您可以对最小和最大部分使用相同的图像。

You can use the same image for both the min and max parts.

这篇关于更改iPhone UISlider条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆