One of the features that Xojo has is a Modal MsgBox/MessageDialog, that provides information to the user and waits for a response. The standard UIAlertViewController in Swift is what is “normally” used for this function, but requires a lot of code to set up the buttons, the action events etc. But one of the things I didn’t like was if you had more that two buttons, it STACKED them. My class leaves them Horizontal
In addtion, there is an INPUTBOX version with a single TextField
I will not be posting all the code for this class as it exceeds 740+ lines. And while this is a lot of code, you just add the class to a project and forget about it.
- Does not require declared instances of the MsgBox class on each ViewController that needs to use it, and only requires the Delegate Protocol to be declared if the Msgbox will be used for more than notifications (ie. just an OK button)
- Provides only TWO action delegates… ‘action’ which indicates what button, and ‘getInput’ to return value of an InputBox [both are optional]
- Colors, fonts, borders etc. are 100% customizable so you can skin the MsgBox to meet the theme of your App (this is what makes up a bulk of the code to be honest)
theMsgBox.caption = "This is the Title" theMsgBox.message = "This is a\nmultiline message." theMsgBox.buttons = .OkCancel theMsgBox.showAlert("boxid")
theMsgBox.caption = "This is the Title" theMsgBox.message = "Enter Players Name" theMsgBox.buttons = .InputBox theMsgBox.inputText = "dave" theMsgBox.format = .Anything // default value theMsgBox.dismissOnRETURN = true theMsgBox.showAlert("input")
- .format allows inputbox to filter input.
- .Anything = accepts, well anything, this is the default
- .AnyInteger = accepts, only Integer value [digits,+,-]
- .AnyDouble = accepts,Double value [digits,+,- and . ]
- .PosInteger = accepts, only Positive Integer value [digits only]
- .PosDouble = accepts, Positive Double value [digits and . ]
- .buttons define which buttons are displayed [OK is default if not specified], and yes, these were borrowed from VB6
- .InputBox - specifies Inputbox with Cancel and OK buttons
In addition to .buttons there is .custom that allows up to 3 buttons with captions of the developers choosing.
theMsgBox.caption="GAME OVER" theMsgBox.message="There are no move moves." theMsgBox.custom=["Play Again?","Restart this Game","Exit"] theMsgBox.showAlert("GAMEOVER")
This also shows how it can be skinned… Something you cannot do with UIAlertViewController