Skip to content

Instantly share code, notes, and snippets.

@donchan922
Last active October 21, 2022 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donchan922/614ed862f7c7146fc0c94631189978d8 to your computer and use it in GitHub Desktop.
Save donchan922/614ed862f7c7146fc0c94631189978d8 to your computer and use it in GitHub Desktop.
import SwiftUI
import GoogleMobileAds
struct AdView: UIViewRepresentable {
func makeUIView(context: Context) -> GADBannerView {
let banner = GADBannerView(adSize: kGADAdSizeBanner)
// 以下は、バナー広告向けのテスト専用広告ユニットIDです。自身の広告ユニットIDと置き換えてください。
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
return banner
}
func updateUIView(_ uiView: GADBannerView, context: Context) {
}
}
struct ContentView: View {
var body: some View {
AdView()
// サイズを変更する場合
// AdView().frame(width: 320, height: 50)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
@Djibs
Copy link

Djibs commented Oct 21, 2022

Hello,
how to embed adView in another UIViewRepresentable. I want to integrate a banner in a wkwebview
Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment