使用模板设置布局

您可以使用标准布局模板:该模板包括所有视觉广告资产的预配置设置,但可以进行自定义。

代码示例
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)

备注

创建您自己的基于模板的设计时,您不必为所有视觉元素进行首选设置。任何没有首选设置的元素都使用默认值进行配置。