简体   繁体   English

UIControlStateHighlighted和UIControlStateSelected之间有什么区别?

[英]What's the difference between UIControlStateHighlighted and UIControlStateSelected?

I am trying to set a state for UIButton. 我正在尝试为UIButton设置一个州。

But i don't know the difference between the UIControlStateHighlighted and UIControlStateSelected . 但我不知道UIControlStateHighlightedUIControlStateSelected之间的区别。

Could anyone help me out? 任何人都可以帮我吗?

Thanks and best regards. 谢谢和最好的问候。

They can mean whatever you want them to, but in general they mean the following: 它们可能意味着你想要的任何东西,但一般来说它们意味着以下内容:

Highlighted = The user is currently interacting with something that will change once they stop interacting (eg holding down a button) 突出显示=用户当前正在与一旦他们停止交互时会改变的事物进行交互(例如,按住按钮)

Selected = The item is current the active item in a group (eg The selected item in a segmented control). 已选择=该项目是当前组中的活动项目(例如,分段控件中的所选项目)。 This can only be achieved by setting it programmatically. 这只能通过以编程方式设置来实现。

  • UIControlStateHighlighted = it highlights the button with some flash(in button background) when the user taps. UIControlStateHighlighted =当用户点击时,它突出显示带有一些闪光的按钮(在按钮背景中)。

  • UIControlStateSelected = it highlights nothing to that button. UIControlStateSelected =它不突出显示该按钮。

From the official doc: 来自官方文件:

UIControlStateHighlighted Highlighted state of a control. UIControlStateHighlighted控件的突出显示状态。 A control enters this state when a touch enters and exits during tracking and when there is a touch up event. 当跟踪期间触摸进入和退出以及有触摸事件时,控件进入此状态。 You can retrieve and set this value through the highlighted property. 您可以通过突出显示的属性检索和设置此值。

UIControlStateSelected Selected state of a control. UIControlStateSelected控件的选定状态。 For many controls, this state has no effect on behavior or appearance. 对于许多控件,此状态对行为或外观没有影响。 But other subclasses (for example, the UISegmentedControl class) may have different appearance depending on their selected state. 但是其他子类(例如,UISegmentedControl类)可能具有不同的外观,具体取决于其选择的状态。 You can retrieve and set this value through the selected property. 您可以通过selected属性检索和设置此值。

Your button get highlighted in reaction of a touch event. 您的按钮会在触摸事件的反应中highlighted It could then be on a selected state within a group (for segmented control). 然后它可以处于组内的selected状态(用于分段控制)。

Highlighted is typically applied transiently when the control is being touched, selected is a more permanent state. 突出显示通常在触摸控件时瞬时应用,选择的是更永久的状态。 Imagine a checkbox type button which dimmed while it was being touched - dimming is highlighted, ticked is selected, unticked is unselected. 想象一个复选框类型按钮,当它被触摸时变暗 - 调暗突出显示,勾选选中,未选中未选中。

Typically you'd never set highlighted status manually as the system will be setting/unsettling it in response to touches, whereas selected is safer. 通常,您不会手动设置突出显示的状态,因为系统将根据触摸设置/解除设置,而选择更安全。 This particularly applies to buttons. 这特别适用于按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于自定义的UIButton,我是否真的必须为UIControlStateSelected和UIControlStateHighlighted设置图像 - For customized UIButton, do I really have to set image for UIControlStateSelected and UIControlStateHighlighted 这些进口之间有什么区别? - What's the difference between these imports? Iphone中的ModalViewController和NonModalViewController有什么区别? - What's the difference between a ModalViewController and NonModalViewController in Iphone? UIImageView的框架和边界之间有什么区别? - What's the difference between frame and bounds of a UIImageView? -existingObjectWithID:error:和-objectWithID:?之间有什么区别? - What's the difference between -existingObjectWithID:error: and –objectWithID:? UIClass和UIClassController有什么区别? - What's the difference between a UIClass and UIClassController? 使用 CGFloat 和 float 有什么区别? - What's the difference between using CGFloat and float? InstantiateInitialViewController和InstantiateViewControllerWithIdentifier之间有什么区别? - What's the difference between instantiateInitialViewController and instantiateViewControllerWithIdentifier:? iOS中的NSCachesDirectory和NSDownloadsDirectory有什么区别? - what's the difference between NSCachesDirectory and NSDownloadsDirectory in iOS? Apple 音频框架之间有什么区别? - What's the difference between the Apple audio frameworks?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM