I am trying to give vertical space constraint programatically for Admob native ads compenents by using NSLayoutConstraint.
I assigned nativeAdView in the ListTileNativeAdFactory class.
(I used this guide : https://codelabs.developers.google.com/codelabs/admob-inline-ads-in-flutter#7)
let nativeAdView = nibView as! GADNativeAdView
In fact I can give height constraint without a problem.
This code works without a problem:(It gives height constraint to nativeAdView.mediaView)
if let mediaView = nativeAdView.mediaView{
NSLayoutConstraint(
item: mediaView,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: 120).isActive = true
}
On the other hand, If I try to give vertical space constraint(top) with this code:
if let mediaView = nativeAdView.mediaView, let calltoActionView = nativeAdView.callToActionView{
NSLayoutConstraint(
item: mediaView,
attribute: NSLayoutConstraint.Attribute.top,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: calltoActionView,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: 15).isActive = true
}
It gives Unknown layout attribute error.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <GADMediaView: 0x11c0552e0; frame = (35 369.5; 250 150); autoresize = RM+BM; layer = <CALayer: 0x2801e2f00>>: Unknown layout attribute' terminating with uncaught exception of type NSException
I'm using Google's official NativeAdView file.
How can I solve this problem?