ios Facebook add FBNativeAdView as Subview

Giru Bhai

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.

Giru Bhai

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to add subview inside UIAlertView for iOS 7?

分類Dev

Remove subview on viewdisappear add again when appear - not working- ios sdk

分類Dev

ios: autolayout animation, how to prevent the subview be animated?

分類Dev

UILabel not showing subview in iOS8

分類Dev

Add subview to current view's UINavigationBar only

分類Dev

iOS UIButton text colour doesn't change after adding subview

分類Dev

iOS LayoutSubviews being called multiple times when a subview resizes

分類Dev

Facebook iOS 3.7 FacebookAppId

分類Dev

can people see Facebook IOS app on their facebook?

分類Dev

iOS: Login to Facebook through app

分類Dev

Facebook SDK 4.5 IOS 9

分類Dev

iOS UIActivityViewController missing Facebook option

分類Dev

Swift 3 add remove subviewとそのコンテンツを動的に

分類Dev

IOS add shadow to UIButton

分類Dev

iOS 8.3 and later, Facebook share text not inserted

分類Dev

How to create clickable label Like Facebook in ios?

分類Dev

iOS Facebook Login Access Token refresh

分類Dev

Интеграция Facebook и Twitter в Xcode Scenes Swift iOS

分類Dev

how to check if already logged in Facebook in ios?

分類Dev

How to fetch Facebook user information in ios

分類Dev

Get invitable_friends Facebook API iOS

分類Dev

Facebook iOS SDK 4.0 "App Invites" sent without iOS notification

分類Dev

Facebook App Events - track facebook add clicks resulting in app install conversations - without Facebook SDK?

分類Dev

Emberjs loading dynamic subview

分類Dev

Create a UIView to use as a subView

分類Dev

Can I use the Facebook iOS SDK to open a user's Facebook profile?

分類Dev

Xamarin Facebook iOS10 SDKcom.facebook.sdk.loginコード= 308

分類Dev

Design for Facebook authentication in an iOS app that also accesses a secured web service

分類Dev

Facebook IOS SDKURLスキームの生成

Related 関連記事

  1. 1

    How to add subview inside UIAlertView for iOS 7?

  2. 2

    Remove subview on viewdisappear add again when appear - not working- ios sdk

  3. 3

    ios: autolayout animation, how to prevent the subview be animated?

  4. 4

    UILabel not showing subview in iOS8

  5. 5

    Add subview to current view's UINavigationBar only

  6. 6

    iOS UIButton text colour doesn't change after adding subview

  7. 7

    iOS LayoutSubviews being called multiple times when a subview resizes

  8. 8

    Facebook iOS 3.7 FacebookAppId

  9. 9

    can people see Facebook IOS app on their facebook?

  10. 10

    iOS: Login to Facebook through app

  11. 11

    Facebook SDK 4.5 IOS 9

  12. 12

    iOS UIActivityViewController missing Facebook option

  13. 13

    Swift 3 add remove subviewとそのコンテンツを動的に

  14. 14

    IOS add shadow to UIButton

  15. 15

    iOS 8.3 and later, Facebook share text not inserted

  16. 16

    How to create clickable label Like Facebook in ios?

  17. 17

    iOS Facebook Login Access Token refresh

  18. 18

    Интеграция Facebook и Twitter в Xcode Scenes Swift iOS

  19. 19

    how to check if already logged in Facebook in ios?

  20. 20

    How to fetch Facebook user information in ios

  21. 21

    Get invitable_friends Facebook API iOS

  22. 22

    Facebook iOS SDK 4.0 "App Invites" sent without iOS notification

  23. 23

    Facebook App Events - track facebook add clicks resulting in app install conversations - without Facebook SDK?

  24. 24

    Emberjs loading dynamic subview

  25. 25

    Create a UIView to use as a subView

  26. 26

    Can I use the Facebook iOS SDK to open a user's Facebook profile?

  27. 27

    Xamarin Facebook iOS10 SDKcom.facebook.sdk.loginコード= 308

  28. 28

    Design for Facebook authentication in an iOS app that also accesses a secured web service

  29. 29

    Facebook IOS SDKURLスキームの生成

ホットタグ

アーカイブ