A
A
Adpluginx Documentation
Ask or search…
⌃K
Comment on page

Init Native View to Swift Class

  1. 1.
    Now Add Another file to Runner
  2. 2.
    This time select Swift and name it SingisticNativeAdFactory
  3. 3.
    Now open SingisticNativeAdFactory and replace it by below code.
SingisticNativeAdFactory.swift
1
import google_mobile_ads
2
​
3
import UIKit
4
​
5
class SingisticNativeAdFactory : FLTNativeAdFactory {
6
​
7
func createNativeAd(_ nativeAd: GADNativeAd,
8
customOptions: [AnyHashable : Any]? = nil) -> GADNativeAdView? {
9
let nibView = Bundle.main.loadNibNamed("NativeAdView", owner: nil, options: nil)!.first
10
​
11
​
12
let nativeAdView = nibView as! GADNativeAdView
13
​
14
(nativeAdView.headlineView as! UILabel).text = nativeAd.headline
15
nativeAdView.headlineView!.isHidden = nativeAd.headline == nil
16
​
17
​
18
(nativeAdView.bodyView as! UILabel).text = nativeAd.body
19
nativeAdView.bodyView!.isHidden = nativeAd.body == nil
20
​
21
(nativeAdView.callToActionView as! UIButton).setTitle(nativeAd.callToAction, for: .normal)
22
nativeAdView.callToActionView!.isHidden = nativeAd.callToAction == nil
23
​
24
(nativeAdView.iconView as! UIImageView).image = nativeAd.icon?.image
25
nativeAdView.iconView!.isHidden = nativeAd.icon == nil
26
​
27
(nativeAdView.storeView as! UILabel).text = nativeAd.store
28
nativeAdView.storeView!.isHidden = nativeAd.store == nil
29
​
30
(nativeAdView.priceView as! UILabel).text = nativeAd.price
31
nativeAdView.priceView!.isHidden = nativeAd.price == nil
32
​
33
(nativeAdView.advertiserView as! UILabel).text = nativeAd.advertiser
34
nativeAdView.advertiserView!.isHidden = nativeAd.advertiser == nil
35
​
36
nativeAdView.callToActionView?.isUserInteractionEnabled = false
37
​
38
nativeAdView.nativeAd = nativeAd
39
​
40
return nativeAdView
41
}
42
}