ios Facebook将FBNativeAdView添加为Subview [英] ios Facebook add FBNativeAdView as Subview
问题描述
我想使用 FBNativeAdView
中的预建视图(不想自定义FBNative Ad)。在链接
I want to use prebuilt view from FBNativeAdView
(don't want to customize FBNative Ad).As given in the link
FBNativeAdView创建预建的原生广告模板视图,
管理原生广告。
The FBNativeAdView creates prebuilt native ad template views and manages native ads.
而且我更改了 NativeAdSample 示例,在 Facebook SDK 中给出。并添加 FBNativeAdView
作为mainView(adUIView)的子视图。
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];
}
所以问题是如何添加 fbNativeAdView
作为父视图的子视图,所以它应该在父视图中查看。我做了
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];
没有成功。
本机广告模板提供有关如何获取 FBNativeAdView的信息
从 FBNativeAd
。但没有告诉过如何在uiview中使用 FBNativeAdView
/ p>
Native Ad Template gives information about how to get FBNativeAdView
from FBNativeAd
.But didn't told about how to use FBNativeAdView
in uiview.
推荐答案
现在使用 FBNativeAdView
作为
fbNativeAdView.frame = CGRectMake(0, 0, 320, 120);
此外现在本机广告模板提供了有关如何在uiview中使用 FBNativeAdView
的信息。
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];
}
这篇关于ios Facebook将FBNativeAdView添加为Subview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!