Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios Facebook add FBNativeAdView as Subview

I want to use prebuilt view from FBNativeAdView(don't want to customize FBNative Ad).As given in the link

The FBNativeAdView creates prebuilt native ad template views and manages native ads.

And I did Changed NativeAdSample example given in Facebook SDK.And add FBNativeAdView as a subview of mainView(adUIView).

-(void) nativeAdDidLoad: (FBNativeAd * ) nativeAd 
{
        NSLog(@"Native ad was loaded, constructing native UI...");

        if (self._nativeAd) 
        {
            [self._nativeAd unregisterView];
        }

        self._nativeAd = nativeAd;

        // Here I did add
        FBNativeAdViewAttributes * attributes = [[FBNativeAdViewAttributes alloc] init];
        attributes.backgroundColor = [UIColor whiteColor];
        attributes.titleColor = [UIColor blackColor];

        FBNativeAdView * fbNativeAdView = [FBNativeAdView nativeAdViewWithNativeAd: self._nativeAd withType: FBNativeAdViewTypeGenericHeight300 withAttributes: attributes];
}

So the question is how to add fbNativeAdView as a subview of ParentView so it should view in parent view.I did it

[self.adUIView addSubview:fbNativeAdView];

with no success.

Native Ad Template gives information about how to get FBNativeAdView from FBNativeAd.But didn't told about how to use FBNativeAdView in uiview.

like image 259
Giru Bhai Avatar asked Sep 04 '15 06:09

Giru Bhai


1 Answers

Now It work using add frame in FBNativeAdView as

fbNativeAdView.frame = CGRectMake(0, 0, 320, 120);

Also now Native Ad Template gives information about how to use FBNativeAdView in uiview.

The ad template can be customized by changing the values of its elements:

- (void)nativeAdDidLoad:(FBNativeAd *)nativeAd 
{
  FBNativeAdViewAttributes *attributes = [[FBNativeAdViewAttributes alloc] init];

  attributes.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  attributes.buttonColor = [UIColor colorWithRed:0.4 green:0.9 blue:0.8 alpha:1];
  attributes.buttonTitleColor = [UIColor whiteColor];

  FBNativeAdView *adView = [FBNativeAdView nativeAdViewWithNativeAd:nativeAd 
      withType:FBNativeAdViewTypeGenericHeight300 withAttributes:attributes];

  [self.view addSubview:adView];

  CGSize size = self.view.bounds.size;
  CGFloat xOffset = size.width / 2 - 160;
  CGFloat yOffset = (size.height > size.width) ? 100 : 20;
  adView.frame = CGRectMake(xOffset, yOffset, 320, 300);

  // Register the native ad view and its view controller with the native ad instance
  [nativeAd registerViewForInteraction:adView withViewController:self];
}
like image 82
Giru Bhai Avatar answered Nov 07 '22 03:11

Giru Bhai