Follow

Show banners

View original article on our GitHub
To display banners in your app, follow the following steps:

1. In your view controller declare STABannerView at the begin of the class.

// ViewController.swift 

var startAppBanner: STABannerView?

2. Create and initialize your STABannerView variable and add it as a subView to the view where you want it to be displayed.

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        if !startAppBanner {
            startAppBanner = STABannerView(size: STA_AutoAdSize, autoOrigin: STAAdOrigin_Bottom, withView: self.view, withDelegate: nil);
            self.view.addSubview(startAppBanner)
        }
    }

The STA_AutoAdSize detects the width of the device's screen in its current orientation, and provides the optimal banner for this size.

NOTE: this example shows the banner at the bottom of the root view controller (self.view), but you can pass any other view where you want to show the banner

3. Implement didRotateFromInterfaceOrientation in your view controller

// YourViewController.swift 
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)  {
        // notify StartApp auto Banner orientation change           
        startAppBanner!.didRotateFromInterfaceOrientation(fromInterfaceOrientation)       
        super.didRotateFromInterfaceOrientation(fromInterfaceOrientation)
    }

4. If your app supports iOS 8, implement viewWillTransitionToSize in your view controller

// YourViewController.m
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
        // notify StartApp auto Banner orientation change
        startAppBannerAuto!.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
        startAppBannerFixed!.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    }

Positioning the banner

The origin of the banner is determined by the "autoOrigin" parameter which can receive one of the following values

ValuePositionBehavior
STAAdOrigin_Top Auto Top The banner will be centered and pinned to the top of the view. In case the view is a root view controller, the banner will be located under the status bar, if exists.
STAAdOrigin_Bottom Auto Bottom The banner will be centered and pinned to the bottom of the view.

NOTE
If you wish to use a fixed origin for the banner, please refer to the "Advanced Manual"

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments