Setting up the layout using a template
You can use the standard layout template: The template includes pre-configured settings for all visual ad assets, though they can be customized.
Code example
let bannerView = NativeBannerView()
bannerView.ad = ad
view.addSubview(bannerView)
let appearance = MutableNativeTemplateAppearance.default()
let orangeColor = UIColor(red: 1, green: 176.0/255, blue: 32.0/255, alpha: 1)
let blueColor = UIColor(red: 0, green: 170.0/255, blue: 1, alpha: 1)
appearance.borderColor = orangeColor
let ratingAppearance = appearance.ratingAppearance?.mutableCopy() as? MutableRatingAppearance
ratingAppearance?.filledStarColor = orangeColor
appearance.ratingAppearance = ratingAppearance
let callToActionTextAppearance = LabelAppearance(font: .systemFont(ofSize: 14), textColor: blueColor)
let callToActionAppearance = ButtonAppearance(
textAppearance: callToActionTextAppearance,
normalColor: .clear,
highlightedColor: .gray,
borderColor: blueColor,
borderWidth: 1
)
appearance.callToActionAppearance = callToActionAppearance
appearance.ageAppearance = LabelAppearance(font: .systemFont(ofSize: 12), textColor: .gray)
appearance.titleAppearance = LabelAppearance(font: .systemFont(ofSize: 14), textColor: .black)
appearance.bodyAppearance = LabelAppearance(font: .systemFont(ofSize: 12), textColor: .gray)
let imageConstraint = SizeConstraint(type: .fixed, value: 60)
appearance.imageAppearance = ImageAppearance(widthConstraint: imageConstraint)
bannerView.apply(appearance)
Note
When creating your own template-based design, you don't have to make the preferred settings for all the visual elements. Any elements that don't have preferred settings are configured with the default values.
Was the article helpful?
Previous
Next