How to enable a button in different cases in swift?
You never call imageDidChange
after you changed the text.
Use:
func textViewDidEndEditing(_ textView: UITextView) {
if postTextView.text.isEmpty {
postTextView.text = "Schreibe etwas..."
postTextView.textColor = UIColor.lightGray
}
imageDidChange()
}
How to enable a currently disabled button in Swift
viewWillAppear()
is called every time, before your view controller loads. When you dismiss your imagePicker, and go back to presenting your original viewController that viewWillAppear()
would be called again, and it would override your actionButton.isEnable = true
to being false again. If I were you, I would disable the button in viewDidLoad()
, which is called only once.
Enable user interaction of a button SWIFT
In iOS and OS X development you have so-called outlets
that are variables pointing to UI elements. You can read more about them here.
To declare an outlet, you prefix your variable with @IBOutlet
like so:
@IBOutlet weak var button: UIButton!
and then you need to connect your outlet to the button in your xib
file. That can be done in several ways, but if you have declared a variable like the above, you can:
- go to your storyboard
- in the document outline hold down the control button
- while holding down the control button, you drag from your
files owner
orViewController
to theUIButton
you'd like to connect to - select the outlet you'd like to connect to (
button
in this case)
As shown here
Once that is in place, you are free to use enable your button (and much more) in your code, for instance:
func viewDidLoad() {
super.viewDidLoad()
button.enabled = false
}
You can read more about IBOutlets here
And here is another way to connect outlets (this is how I prefer to connect outlets actually, you define and connect in one go)
Hope that helps
Eureka Forms Swift enable and disable button
I had the same problem, the following code get the errors count if it is 0 the form is OK and proceeds to your next function if it has any errors it does nothing.
<<< ButtonRow() { (row: ButtonRow) -> Void in
row.title = "LOGIN"
}
.onCellSelection { [weak self] (cell, row) in
print("validating errors: \(row.section?.form?.validate().count)")
if row.section?.form?.validate().count == 0{
self?.loginAction(row)
}
}
Disable a Button
The boolean value for NO
in Swift is false
.
button.isEnabled = false
should do it.
Here is the Swift documentation for UIControl
's isEnabled
property.
iOS Swift 5 unable to disable button in custom view
I don't believe there is anything wrong with your code.
When you select a color other than the default for a UIButton
, you also need to select a color for the Disabled state.
Select Default Text Color:
Change State Config to Disabled and select a Text Color:
Now, in Storyboard, you can see the difference when you toggle the Enabled checkbox:
(I selected Blue for Disabled just to make it clear it's not using the "default gray")
Enable a button if all the UITextFields are filled and one of them has an Int value
Connect this @IBAction
to both text fields, for Editing Changed
:
@IBAction func textFieldEdited(_ sender: Any) {
// reset to disabled every time a text field value changes
// will be set to enabled if data is validated
idCheckButton.isEnabled = false
// make sure idTextField has text
guard let idText = idTextField.text, idText != "" else {
return
}
// make sure targetsTextField has text
guard let targetsText = targetsTextField.text, targetsText != "" else {
return
}
// make sure targetsTextField has only numbers
guard targetsText.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil else {
return
}
// enable the button
idCheckButton.isEnabled = true
}
This will be called with every character entered in either of the fields. It:
- first resets the button to
.isEnabled = false
- then checks to see if the id text field has text
- then checks to see if the targets text field has text
- then checks to see that the targets field has only numbers
If it makes it through all 3 checks, it sets the button to .isEnabled = true
swift how to get a button inside a switch statement
The action in this line:
btnThree.addTarget(self, action: "btnThreeclicked:", forControlEvents: .TouchUpInside) //add button action
must match the name of the method you want called - which is presumably this function:
@IBAction func buttonAclicked(sender: UIButton)
so amend the line to:
btnThree.addTarget(self, action: "buttonAclicked:", forControlEvents: .TouchUpInside) //add button action
Related Topics
How to Create Nested Dictionary Elements in Swift
Support Arkit in Lower End Devices
Swiftui Published Updates Not Refreshing
How to Loop Over The Output of a Publisher with Combine
Filter, Closure, Functional Syntax Version of for Loop with Multiple Conditions
Using Scenekit for Hittesting Not Returning a Hit with Scnnode
Editable Nstextview from Interface Builder
Swift: Tvos Ibaction for UIcontrol in Collection View Cell Never Gets Called
How to Refer to a Global Type from Within a Class That Has a Nested Type with The Same Name
How to Prevent SQL Injections with User-Search-Terms in Vapor 4 (Fluent 4)
Decoding Different Type with and Without Array
Why Do I Get Rgb Values of (0,0,0) for an Nsimage with a Transparent Background
Closure Identity in Swift: Unregister Observing Closure
Swift: Get The Compile Time Name of Variable (Referencing to a Class)