Follow

Showing Banners

View original article on our GitHub
To display banners in your app, add a STABannerView to your application according to the following steps:

1. In the header file of your view controller, import STABannerView.h andSTABannerSize.h and declare an STABannerView instance variable

// YourViewController.h

#import <UIKit/UIKit.h>
#import <StartApp/StartApp.h>

@interface YourViewController : UIViewController 
{
    STABannerView* bannerView;
}

2. Create and initialize the STABannerView and add it as a subView to the view where you want it to be displayed. Remember to release the bannerView object in yourdealloc() function in case you're not using ARC in your project

// YourViewController.m

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
     if (bannerView == nil) {
        bannerView = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top     
                                            withView:self.view withDelegate:nil];
        [self.view addSubview:bannerView];
    }
}

- (void) dealloc
{
    // Don't release bannerView if you are using ARC in your project
    [bannerView release];  // Add this line
    [super dealloc];
}

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

NOTE:

  • You can find your "developerId" and "appId" the same way as in step 3 above
  • This example shows the banner at the top 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.m

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [bannerView didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];    
}

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

// YourViewController.m

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [bannerView 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?
0 out of 1 found this helpful
Have more questions? Submit a request

Comments