To add a button that submits in Swift, you can use the UIButton
class which inherits from UIControl
.
main.swift220 chars5 lines
In the code above, we create a button of type system
with the title "Submit". We then add a target to the button that will execute an action when the button is tapped. In this case, we're calling a function called submitButtonTapped
.
To actually handle the button tap, you need to define the submitButtonTapped
function:
main.swift124 chars5 lines
In this function, you can add code to handle the submission. Note that we prefix the function with @objc
annotation, which is required when adding targets from UIButton
objects.
With these two pieces of code, you should now have a button that submits in your iOS Swift application.
gistlibby LogSnag