instruction from Google是Storyboard
方法。如何顯示Admob橫幅頂部沒有使用Storyboard
?我試圖把它放在的this code。未使用Storyboard加載Admob(Swift)
我試圖把這個放在viewDidLoad
下,但它不起作用。
override func viewDidLoad() {
super.viewDidLoad()
var bannerView: GADBannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.adUnitID = "ca-app-pub-MYID"
bannerView.rootViewController = self
bannerView.loadRequest(GADRequest())
view.addSubview(bannerView)
mainScrollView = UIScrollView(frame: self.view.bounds)
mainScrollView.pagingEnabled = true
mainScrollView.showsHorizontalScrollIndicator = false
mainScrollView.showsVerticalScrollIndicator = false
pageScrollViews = [UIScrollView?](count: photos.count, repeatedValue: nil)
let innerScrollFrame = mainScrollView.bounds
mainScrollView.contentSize =
CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width,
mainScrollView.bounds.size.height)
print(mainScrollView.contentSize)
mainScrollView.backgroundColor = UIColor.blackColor()
mainScrollView.delegate = self
self.view.addSubview(mainScrollView)
configScrollView()
addPageControlOnScrollView()
}
您需要在視圖控制器中使用addsubView()添加bannerView。 – Harry