I am trying to specify custom font for admob native ads CTA button.
But I’m getting this error.
Value of type ‘UIView?’ has no member ‘titleLabel’
ListTileNativeAdFactory:
class ListTileNativeAdFactory : FLTNativeAdFactory {
...
...
(nativeAdView.callToActionView as? UIButton)?.setTitle(nativeAd.callToAction, for: .normal)
nativeAdView.callToActionView.titleLabel.font = UIFont(name: "Arial", size: 20)//This line gives error!
...
...
return nativeAdView
}
How can I solve my problem? Thanks…
2
Answers
I solved my problem. We need NSAttributedString & NSMutableAttributedString classes.
https://developer.apple.com/documentation/foundation/nsattributedstring
https://developer.apple.com/documentation/foundation/nsmutableattributedstring
For nativeAdView, don't use setTitle method, instead use
setAttributedTitle method.
As a result,
The solution:
You’d need to repeat what you did on the line above:
(nativeAdView.callToActionView as? UIButton)?
. Or wrap these two lines in aif
clause