...
The SDK provides a universal way to display advertisements inside the cell of scrollable controls, such as UITableView and UICollectionView.
Info |
---|
We need you to edit your item Layout, so it has a wrapper/holder for the Ads. Keep in mind this wrapper/holder could be expanded or contracted, so make sure your layout adapts to this changes, this size changes in the layout will be limited by the ad configurations that your technical account manager can edit. This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll. |
Using a UITableView
Get the UITableView
Code Block |
---|
|
import UIKit
import R89SDK
class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView:UITableView!
...
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: self.view.bounds, style: .plain)
// RegisterTable a cell classview configurations.
tableView.register(InfScrlViewCell.self, forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self
tableView.estimatedRowHeight = 300
tableView.rowHeight = UITableView.automaticDimension
self.view.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
...
}
...
} |
Adding the wrapper to the item
The adContainer
will play the role of a wrapper inside the UITableViewCell
’s contentView
.
Code Block |
---|
|
class InfScrlViewCell: UITableViewCell {
let centeredLabel = UILabel()
// This is the wrapper
let adContainer:UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
// Specify the item ad tag here
view.accessibilityLabel = "infiniteScroll_ad_wrapper_tag"
return view
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(centeredLabel)
// Added the wrapper to the item
contentView.addSubview(adContainer)
// Setup the constraints
...
}
...
} |
...
Code Block |
---|
|
class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView:UITableView!
...
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: self.view.bounds, style: .plain)
// Table view configurations.
...
// Show the ads.
let infiniteScrollConfigId = ConfigBuilder.companion.INFINITE_SCROLL_TEST_R89_CONFIG_ID
RefineryAdFactory.shared.createInfiniteScroll(
configurationID: infiniteScrollConfigId,
scrollView: tableView,
// Specify the item ad tag here as well
scrollItemAdWrapperTag: TableViewInfiniteScrollViewController.tag"infiniteScroll_ad_wrapper_tag",
lifecycleCallbacks: nil
)
}
...
} |
Using a UICollectionView
Get the UICollectionView
Code Block |
---|
|
import UIKit
import R89SDK
class CollectionViewInfiniteScrollViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
var collectionView: UICollectionView!
...
override func viewDidLoad() {
super.viewDidLoad()
// Configure the collection view layout
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
// Configure the collection view
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(DynamicHeightCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
// Add constraints to fill the view
collectionView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(collectionView)
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
...
} |