Preparing the UI placement(s) of your player tag(s)
Warning |
---|
A player tag may be displayed only in one placement view. Displaying the same tag in multiple placement views is not supported and may lead to unexpected behavior. |
...
Code Block |
---|
|
// ViewController.viewDidLoad
let placement = AdPlayerPlacementView(tagId: tagId)
placement.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(placement)
NSLayoutConstraint.activate([
placement.leadingAnchor.constraint(equalTo: view.leadingAnchor),
placement.trailingAnchor.constraint(equalTo: view.trailingAnchor),
placement.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor)
]) |
Placement Sizing
Note |
---|
By default, the SDK will set the placement’s height for you. To override this behavior - set and implement “layoutDelegate“implement AdPlacementLayoutDelegate and set it to `placement.layoutDelegate ` |
Code Block |
---|
|
// ViewController.viewDidLoad
placement.layoutDelegate = self
self.adPlacementHeightConstraint = placement.heightAnchor.constraint(equalToConstant: 0)
extension ViewController: AdPlacementLayoutDelegate {
func adPlacementHeightWillChange(to newValue: CGFloat) {
guard newValue != adPlacementHeightConstraint.constant else { return }
adPlacementHeightConstraint.constant = newValue
}
} |
For an advanced UI layout example please refer to the following:
CollectionView Example -> AdPlacementCollectionViewCell
SwiftUI Example