Tengo varios botones dentro de un view controller, pero hay uno de ellos que quiero que este deshabilitado si en un textfield
no hay ningún valor escrito.
Si se escribe algun valor se debe volver a habilitar.
import UIKit
class AreaOfAnIsoscelesTriangleViewController: UIViewController {
@IBOutlet var texfieldA: UITextField!
@IBOutlet var textfieldB: UITextField!
@IBOutlet var label1: UILabel!
@IBOutlet var label2: UILabel!
@IBOutlet var label3: UILabel!
@IBOutlet var label4: UILabel!
@IBOutlet var label5: UILabel!
@IBOutlet var label6: UILabel!
@IBOutlet var label7: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func calculateButton(_ sender: UIButton) {
textfieldB.resignFirstResponder()
texfieldA.resignFirstResponder()
let numbersquareA = Double(texfieldA.text!)!
let resultSquareA = pow(numbersquareA, 2)
let numbersquare = Double(textfieldB.text!)!
let resultSquare = pow(numbersquare, 2)
let variableA = Double(texfieldA.text!)!
let variableB = Double(textfieldB.text!)!
label1.text = "b * √a^2 - b^2 /4 /2"
label2.text = "\(variableB) * √\(variableA)^2 - \(variableB)^2 /4 /2"
label3.text = "\(variableB) * √\(resultSquareA) - \(resultSquare) /4 /2"
let operation1 = resultSquare / 4
let operation2 = resultSquareA - operation1
label4.text = "\(variableB) * √\(resultSquareA) - \(operation1) /2"
label5.text = "\(variableB) * √\(operation2)/2"
let operation3 = sqrt(operation2)
let operation3final = String(format: "%.2f", operation3)
label5.text = "\(variableB) * \(operation3final)/2"
let operation3intValue = Double(operation3final)
let operation4 = variableB * operation3intValue!
let operation5 = operation4/2
label6.text = "\(operation4)/2"
label7.text = "\(operation5)"
}
@IBAction func bottonstep(_ sender: UIButton) {
let variableA = Double(texfieldA.text!)!
let variableB = Double(textfieldB.text!)!
let numbersquareA = Double(texfieldA.text!)!
let numbersquare = Double(textfieldB.text!)!
let resultSquareA = pow(numbersquareA, 2)
let resultSquare = pow(numbersquare, 2)
let alertControler : UIAlertController = UIAlertController (title: "The steps to follow are those :", message: "Step 1 - (b * √a^2 - b^2 /4 /2).Replace the variable of the equation with its corresponding values in this case would be \(variableB) * √\(variableA)^2 - \(variableB)^2 /4 /2 \n Step 2: To raise numbers according to their exponents \(variableB) * √\(resultSquareA) - \(resultSquare) /4 /2" , preferredStyle: .actionSheet)
let okAction :UIAlertAction = UIAlertAction(title: "ok", style: .default, handler: nil)
alertControler.addAction(okAction)
present(alertControler , animated: true, completion: nil)
}
El boton que necesito que se encuentre deshabilitado si no se ha introducido un valor en el campo de texto es bottonstep
.
Como seria el metodo ? tendría que ponerlo como outlet?