Created
April 13, 2020 07:38
-
-
Save yotubarail/6aa3161dfce6ea299bfcfd53393135f0 to your computer and use it in GitHub Desktop.
Google AdMobのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import GoogleMobileAds | |
class ViewController: UIViewController, GADBannerViewDelegate { | |
var bannerView: GADBannerView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
bannerView = GADBannerView(adSize: kGADAdSizeBanner) | |
addBannerViewToView(bannerView) | |
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716" | |
bannerView.rootViewController = self | |
bannerView.load(GADRequest()) | |
bannerView.delegate = self | |
} | |
func addBannerViewToView(_ bannerView: GADBannerView) { | |
bannerView.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(bannerView) | |
view.addConstraints( | |
[NSLayoutConstraint(item: bannerView, | |
attribute: .bottom, | |
relatedBy: .equal, | |
toItem: bottomLayoutGuide, | |
attribute: .top, | |
multiplier: 1, | |
constant: 0), | |
NSLayoutConstraint(item: bannerView, | |
attribute: .centerX, | |
relatedBy: .equal, | |
toItem: view, | |
attribute: .centerX, | |
multiplier: 1, | |
constant: 0) | |
]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment