Layout without a template

To display native ads, YMANativeAppInstallAd, YMANativeContentAd, and YMANativeImageAd must be bound to a specific View. This View must be defined as the root element for the subview set that the data contained in the native ad will be bound to.

Each ad type corresponds to a specific type of View:

Restriction. Requirements for mediaView size when displaying video ads

Minimum size of an instance of the YMANativeMediaView class, which supports video playback: 300x160 or 160x300.

To support video playback in native ads, we recommend setting the width for mediaView to at least 300. To calculate the appropriate mediaView height value, use the aspectRatio property value.

Layout of native ads

  1. Review the list of required and optional subviews for each type of View.
  2. Set the values for all required subviews. You can do this using nib, or directly in the code. Create an instance of YMANativeAppInstallAdView, YMANativeContentAdView or YMANativeImageAdView and define the subview values in initWithFrame:
    Example of registering a set of subviews:
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self != nil) {
            UILabel *titleLabel = [self label];
            UILabel *bodyLabel = [self label];
            UILabel *ageLabel = [self secondaryLabel];
            UILabel *warningLabel = [self label];
            UILabel *sponsoredByLabel = [self label];
            UILabel *priceLabel = [self label];
            StarRatingView *ratingView = [self starRatingView];
            UIButton *callToActionButton = [self button];
            UIImageView *iconImageView = [self iconAssetImageView];
            YMANativeMediaView *mediaView = [self mediaAssetView];
            [self addSubview:titleLabel];
            [self addSubview:bodyLabel];
            [self addSubview:ageLabel];
            [self addSubview:warningLabel];
            [self addSubview:sponsoredByLabel];
            [self addSubview:callToActionButton];
            [self addSubview:priceLabel];
            [self addSubview:ratingView];
            [self addSubview:iconImageView];
            [self addSubview:mediaView];
            self.titleLabel = titleLabel;
            self.bodyLabel = bodyLabel;
            self.ageLabel = ageLabel;
            self.warningLabel = warningLabel;
            self.sponsoredLabel = sponsoredByLabel;
            self.callToActionButton = callToActionButton;
            self.priceLabel = priceLabel;
            self.ratingView = ratingView;
            self.iconImageView = iconImageView;
            self.mediaView = mediaView;
        }
        return self;
    }
  3. To receive notifications of user interaction with the ad (opening or closing the ad or exiting the app), assign it the YMANativeAdDelegate that implements the methods:
  4. Request the values for native ad assets using the – adAssets method. This will help you calculate the position and sizes of these assets in advance.
    Note.

    It is recommended to display feedbackButton if adAssets.feedbackAvailable returned the value YES. In this case, the reasons for closing the ad will be displayed when feedbackButton is clicked.

    YMANativeAdAssets *assets = [ad adAssets];
    Example of getting the image size and aspect ratio of the ad title text and media
    YMANativeAdImage *image = assets.image;
    NSString *title = assets.title;
    YMANativeAdMedia *media = assets.media;
    NSLog(@"Image size: %@", NSStringFromCGSize(image.size));
    NSLog(@"Title: %@", title);
    NSLog(@"Media aspect ratio: %.2f", media.aspectRatio);
  5. Call the – bindContentAdToView:delegate:error: or – bindAppInstallAdToView:delegate:error: method to bind content to a native ad object.
    - bindContentAdToView:delegate:error:
    // ...
    self.contentAdView = [[YMANativeContentAdView alloc] initWithFrame:frame];
    //configure content ad view
    // ...
    - (void)nativeAdLoader:(null_unspecified YMANativeAdLoader *)loader didLoadContentAd:(id<YMANativeContentAd> __nonnull)ad
    {
        NSError *error = nil;
        BOOL result = [ad bindContentAdToView:self.contentAdView
                                     delegate:self
                                        error:error];
        NSLog(@"Error: %@", error);
    }
    Note.

    If a required element of a native ad has the corresponding YMANativeAppInstallAdView, YMANativeContentAdView, or YMANativeImageAdView property set to nil, binding doesn't occur, and the ad isn't displayed.