Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Converted to Swift 5.5 by Swiftify v5.5.24623 - https://swiftify.com/
- func viewDidLoad() {
- super.viewDidLoad()
- // Задание ширины рекламы
- let adSize = YMAAdSize.stickySize(withContainerWidth: containerWidth())
- // Создание экземпляра adView
- adView = YMAAdView(adUnitID: "R-M-XXXXX-YY", adSize: adSize)
- adView.delegate = self
- addAdView()
- // Загрузка рекламы
- adView.loadAd()
- }
- func addAdView() {
- let adView = self.adView
- adView?.translatesAutoresizingMaskIntoConstraints = false
- let views = [
- "adView" : adView
- ]
- if let adView = adView {
- view.addSubview(adView)
- }
- let horizontal = NSLayoutConstraint.constraints(
- withVisualFormat: "H:|[adView]|",
- options: [],
- metrics: nil,
- views: views)
- let vertical = NSLayoutConstraint.constraints(
- withVisualFormat: "V:[adView]-|",
- options: [],
- metrics: nil,
- views: views)
- view.addConstraints(horizontal)
- view.addConstraints(vertical)
- }
- func containerWidth() -> CGFloat {
- var containerWidth = view.frame.size.width
- if #available(iOS 11.0, *) {
- containerWidth = view.frame.inset(by: view.safeAreaInsets).size.width
- }
- return containerWidth
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement