Shravya Shravya - 1 year ago 84
Swift Question

How to add a common view in all view controllers at the bottom above tab bar

I need to add a view that has some buttons and appears in all the view controllers. The view should contain a horizontal scrollview in which all the buttons are placed.

The view needs to be on top of the tab bar. Similar to the one in the imageThe player in the apple music application, on top of the tab bar in the bottom

Any help is appreciated. Thanks!

Answer Source

Try this:

This is Swift 3 code.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

    view.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-100, width: UIScreen.main.bounds.width , height: 100)

    //Add ScrollView to View
    let scrollview = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
    scrollview.contentSize = CGSize( width: view.frame.size.width*2, height: view.frame.size.height)
    scrollview.backgroundColor =

    //Add Button to Scrollview
    let btn = UIButton(frame: CGRect(x: scrollview.frame.size.width/3, y: scrollview.frame.size.height/2, width: 50, height: 30))
    btn.setTitle("Heloo", for: UIControlState.normal)
    btn.setTitleColor(, for: UIControlState.normal)
    let btn2 = UIButton(frame: CGRect(x: scrollview.frame.size.width/2, y: scrollview.frame.size.height/2, width: 50, height: 30))
    btn2.setTitle("Hiiii", for: UIControlState.normal)
    btn2.setTitleColor(, for: UIControlState.normal)

    window?.insertSubview(view, at: 0)
    window?.bringSubview(toFront: view)

    return true

Hope this help

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download