使用 UISlider 作为 UISwitch (两个状态对象)
注意:我使用的是 Monotouch。
我想知道是否有办法将 UISlider
对象用作 UISwitch
对象。我的意思是...我只想在两种状态(100% 或 0%)下使用 UISlider 对象,并且我想阻止用户交互的其他状态。
我尝试这样做是因为我正在开发一个软件,它将控制某些模块的照明。问题是有些模块带有调光器(0% 到 100%),也有非调光器模块(0% 或 100% 值),并且我需要 UISlider
工作,正如我之前在第二种情况。
UISwitch
的问题是,它在视觉上是一个完全不同的组件,它不像滑块那么薄,而且我无法放置代表 ON 和 OFF 状态的图标(在它旁边,如附图所示),我想知道也许 UI 会因为滑块和开关而变得混乱...
Note: I'm using Monotouch.
I'd like to know if there's a way to use UISlider
object as an UISwitch
object. I mean... I want to use the UISlider
object only in two states (100% or 0%), and I want to block the other states for the user interaction.
I'm trying to do this because I'm developing a software, and it'll control the illumination of some modules. The problem is that there are modules with dimmer (0% through 100%), and non-dimmer modules (0% or 100% value), and I need the UISlider
working as I mentioned before in the second case.
The problem with the UISwitch
is that is a totally different component visually, it's not as thin as the slider and i cannot put icons representing the state of ON and OFF (beside it as in the attached photo), and I was wondering that maybe the UI is gonna be a mess with slider and switchs...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置 UISlider 的目标/操作,并以编程方式强制其达到极端之一。
我将
连续
设置为NO
,然后将滑块设置为接近末端的动画(以使用户更清楚地了解正在发生的情况)。编辑:
根据您的问题,这是一种为值设置动画的典型机制:
You can set the target/action of the
UISlider
and programmatically force it to one of the extremes.I'd set
continuous
toNO
, and then animate the slider to the closer end (to make it more apparent to the user what is happening).Edit:
per your question, here's a typical mechanism to animate a value:
如果您使用 IB,您可以设置滑块的最小值和最大值,因此分别使用 0、1。或者您可以在代码中执行此操作,请参阅下文:
查看此处
或从该帖子复制并粘贴:
它是一个浮点值,因此是 3.0f loat
if you use IB you can set the min and max values for a slider, so use 0, 1 respectively. or you can do it in code, see below:
look here
or coppied and pasted from that post:
its a float value hence the 3.0f loat
我认为您希望滑块捕捉到 0 或 1。使用在此 stackoverflow 问题 并适当地设置您的值。有趣的是,不到 10 分钟前,我刚刚完成了一个捕捉滑块的编码。为了节省点击,这是您想要的代码,从该问题复制/粘贴:
I think you want your slider to snap to 0 or 1. Use the code found in this stackoverflow question and set your values appropriately. Funny coincidence, I just finished coding this upself for a snapping slider not 10 minutes ago. To save clicking, here's the code you want, copy/pasted from that question: