ios Facebook 添加 FBNativeAdView 作为 subview

标签 ios facebook facebook-audience-network

我想使用 FBNativeAdView 中的预构建 View (不想自定义 FBNative 广告)。如 link 中所述

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

我确实更改了 Facebook SDK 中给出的 NativeAdSample 示例.并添加 FBNativeAdView 作为 mainView(adUIView) 的 subview 。

-(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];
}

所以问题是如何将 fbNativeAdView 添加为 ParentView 的 subview ,以便它应该在父 View 中查看。我做到了

[self.adUIView addSubview:fbNativeAdView];

没有成功。

Native Ad Template提供了有关如何从 FBNativeAd 获取 FBNativeAdView 的信息。但没有说明如何在 uiview 中使用 FBNativeAdView

最佳答案

现在它可以在 FBNativeAdView 中使用添加框架作为

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

现在还有 Native Ad Template提供有关如何在 uiview 中使用 FBNativeAdView 的信息。

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];
}

关于ios Facebook 添加 FBNativeAdView 作为 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32391545/

相关文章:

ios - 如何使用 FQL 从群组中获取群组管理员的帖子

javascript - 显示适用于移动网络的 Facebook Audience Network 原生广告

android - 如何在 WebView 下方放置广告

ios - 在 ios iphone 应用程序中处理信用卡

ios - LLDB 和 "<register XY is not available>"

iOS 从应用程序名称获取应用程序图标

ios - iOS-将图像和文本发布到FB用户墙

ios - 如何动态设置 UILabel 宽度?

android - Facebook Audience Network Proguard 设置

安卓工作室问题 : Could not find ads:AdQuality:unspecified