iOS Development

Declaring iOS predefined bar buttons in Swift 2

Continuing the discussion from iOS predefined bar buttons.

Example of creating a predefined bar button programmatically in Swift 2.

Step 1 – Declare the button

This step is done in the view controller that will display the button on the navigation bar.
let rightButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: "newAction:")

Step 2 – Add the button to the navigation bar

self.navigationItem.rightBarButtonItem = rightButton

Step 3 – Declare the function that is called when the button is tapped

func newAction(sender: AnyObject) {
print("In action call")

The system-supplied images for bar buttons items include the following

enum UIBarButtonSystemItem : Int {
case Done
case Cancel
case Edit
case Save
case Add
case FlexibleSpace
case FixedSpace
case Compose
case Reply
case Action
case Organize
case Bookmarks
case Search
case Refresh
case Stop
case Camera
case Trash
case Play
case Pause
case Rewind
case FastForward
case Undo
case Redo
case PageCurl

Show More

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button