Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a button in Xcode 6?

All I want to do is keep a button hidden until another button is pressed.

For example, Button 1 is visible, but Button 2 isn't. When I press Button 1, I need Button 2 to appear.

Also, I am programming in Xcode 6 using Swift.

Thanks in advance!

like image 788
Schuey999 Avatar asked Nov 19 '14 01:11

Schuey999


People also ask

How do I hide the action button in Swift?

Just create an IBOutlet of the same button and set its isHidden property to true once it's tapped. Save this answer.

How do I hide a view in Swiftui?

Use an opacity(_:) modifier with a value of 0 so that the layout accounts for the error message whether or not it's visible. You can also use this strategy for removing a view that doesn't affect other views' placement, like a view inside an overlay(alignment:content:) modifier.

How do you hide a view in Objective C?

hidden = YES; // or view. hidden = NO; or by calling setHidden: [view setHidden:YES]; // or [view setHidden:NO];


1 Answers

The sample code for hiding a button in Swift:

import UIKit

class ViewController: UIViewController {

// Create outlet for both the button
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    //Set button2 hidden at start
    button2.hidden = true
}



//Here is the action when you press button1 which is visible
@IBAction func button1(sender: AnyObject) {
    //Make button2 Visible
    button2.hidden = false
    }

}

May be this can help you.

like image 80
Dharmesh Kheni Avatar answered Oct 26 '22 05:10

Dharmesh Kheni