Skip to content

Integrating Inline Ad

Vladas Drejeris edited this page Jun 3, 2021 · 4 revisions

Basic Inline Ad Implementation

It is very easy to use Adform Advertising SDK to place ad banners in your application. The example code provided below shows you how to add an inline ad to your view controller. You just need a Master Tag Id and you can display ads in your application.

There are two options to add ads inside your application content, you can use AdInline and AdHesion classes. For this example, we will use AdInline. Let's add one ad in your view controllers viewDidLoad method.

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    //Create a new ad inline object with Master tag id.
    let adView = AFAdInline(masterTagId: masterTag, presenting: self)
        
    //Set ad views frame to place ad centered in the screen just below the status bar.
    adView.frame = CGRect(
        x: (self.view.frame.size.width - adView.adSize.width) / 2,
        y: 20,
        width: adView.adSize.width,
        height: 0
    )
        
    //Add the newly created ad view as a subview to your view controller's view.
    view.addSubview(adView)
        
    //Initiate ad loading.
    adView.loadAd()
}
Objective-C
#import <AdformAdvertising/AdformAdvertising.h>

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //Create a new ad inline object with Master tag id.
    AFAdInline *adView = [[AFAdInline alloc] initWithMasterTagId:mtag presentingViewController:self];
    	
    //Set ad views frame to place ad centered in the screen just below the status bar.
    adView.frame = CGRectMake((self.view.frame.size.width - adView.adSize.width) / 2, 20, adView.adSize.width, 0);
    	
    //Add the newly created ad view as a subview to your view controller's view.
    [self.view addSubview:adView];
    
    //Initiate ad loading.
    [adView loadAd];
}

That's it! You are ready to go.

Sample code:

For a complete example of how to integrate Adform inline ads into your application, check out the sample app.

Clone this wiki locally