I want to use the press of a button to toggle the hidden state of a couple of UILabels. Press the button once, it unhides them, press again the labels are hidden, the default state for these labels being hidden.
Here is what I thought would work (but obviously does not):
@IBAction func information(sender: AnyObject, forEvent event: UIEvent)
{
if(infoLocation.hidden = true)
{
self.infoLocation.hidden = false
}
else
{
self.infoLocation.hidden = true
}
//**********************************//
if(infoName.hidden = true)
{
self.infoName.hidden = false
}
else
{
self.infoName.hidden = true
}
//**********************************//
if(infoVersion.hidden = true)
{
self.infoVersion.hidden = false
}
else
{
self.infoVersion.hidden = true
}
}
Use one trigger to quickly toggle between an object's current state and its hidden or disabled state. For example, easily create buttons that show/hide additional info or hints. Check out the comparison below: In the trigger wizard, select the Change state of action.
The label no longer being hidden is impacted by the Summer '18 change where many base lightning components no longer automatically include the slds-form_inline or slds-form--inline CSS class. The slds-form_inline (formerly slds-form--inline) style was removed. When applied, the style made the element’s width unchangeable.
Toggle Hide and Show Click the button! Toggle (Hide/Show) an Element Step 1) Add HTML: Example <button onclick="myFunction()">Click Me</button>
Choose either the Hidden or the Disabled state and set up your trigger event (e.g., when a button is clicked). Toggle hidden/disabled state triggers are exclusive to Storyline 360 starting with the July 2022 update. Project files that use this feature won't open in previous versions of Storyline 360 and Storyline 3.
To make the code shorter (and look better) I would do like this if its just a toggle:
for label in [label1, label2, label3, label4] {
label.hidden = !label.hidden
}
This will toggle label1-4.hidden
Use ==
inside of your if
statement, not =
.
if(infoVersion.hidden == true)
=
is for assignment.==
is for equality.
update :
You can use a faster version code to toogle hidden status :
infoVersion.hidden = !infoVersion.hidden;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With