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
}

Tags
Show More

Leave a Reply

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