Is it possible to add UIView (Admob) in uitableviewcontroller or in uicollectionviewcontroller

拈花ヽ惹草 提交于 2019-12-30 13:31:09

问题


I want to add admob in uitableviewcontroller or in uicollectionviewcontroller at the bottom of screen. So for that I have to add uiView (GAD BannerView) at the bottom of uitableview controller or uicolleectionview controller. So how can I do this? Actually we can add uiview easily in uiviewcontroller but how can I add this in uitableviewcontroller or uicollectionviewcontroller?


回答1:


Yes you can also add Ad Mob in UITableView or UICollectionView.UITableViewController have a one property toolbar. You can add AdMob to Toolbar as below.

    [self.navigationController setToolbarHidden:NO];
    self.banner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    self.banner.adUnitID = @"ca-app-pub-XXXXXXXX/XXXXXXXXX";
    self.banner.rootViewController = self;
    [self.navigationController.toolbar addSubview:self.banner];

    GADRequest *request;
    [self.banner loadRequest:request];



回答2:


Yes, Its possible. you can add banner ad in header or footer view of tableview or collectionview. Like this in table view

UIView * bannerView = [[UIView alloc]initWithFrame:CGRectMake(0, 10,[[UIScreen mainScreen] bounds].size.width, 50)];

[bannerView setBackgroundColor:[UIColor clearColor]];

_tableView.tableFooterView = bannerView;


来源:https://stackoverflow.com/questions/37069488/is-it-possible-to-add-uiview-admob-in-uitableviewcontroller-or-in-uicollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!