Skip to content

Toolbar 1

Azmal Tech edited this page Jan 12, 2017 · 1 revision

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() { super.viewDidLoad()

view.backgroundColor = UIColor.lightGray

//Toolbar 1
let toolbar1 = UIToolbar()
toolbar1.sizeToFit()
toolbar1.center = CGPoint(x: self.view.frame.width/2, y: 100)
toolbar1.backgroundColor = UIColor.orange

//Aligh Left
let cancel = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: nil)
toolbar1.items = [cancel]

//Toolbar 2
let toolbar2 = UIToolbar()
toolbar2.sizeToFit()
toolbar2.center = CGPoint(x: self.view.frame.width/2, y: 200)
toolbar2.backgroundColor = UIColor.blue

//Aligh Right
let flexible = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
let search = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: nil)
toolbar2.items = [flexible, search]

//Toolbar 3
let toolbar3 = UIToolbar()
toolbar3.sizeToFit()
toolbar3.center = CGPoint(x: self.view.frame.width/2, y: 300)
toolbar3.backgroundColor = UIColor.green

//Alight Left and Right
let stop = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: nil)
let add = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: nil)
toolbar3.items = [stop, flexible, add]

view.addSubview(toolbar1)
view.addSubview(toolbar2)
view.addSubview(toolbar3)

}

}

Clone this wiki locally