Skip to content

Commit

Permalink
Added Ad Choices Icon to Objective-C Custom Native Samples.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627537169
  • Loading branch information
nventimigli authored and maddevrelgithubbot committed May 14, 2024
1 parent 3f0e604 commit f2661bc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="22504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -15,10 +13,13 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LKB-aH-scG">
<rect key="frame" x="360" y="652" width="15" height="15"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" placeholderIntrinsicWidth="375" placeholderIntrinsicHeight="24" text="Headline" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EJ7-Y2-nrO">
<rect key="frame" x="5" y="5" width="365" height="24"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hoj-tc-K51">
Expand All @@ -32,7 +33,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Caption" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Opb-BT-xiP">
<rect key="frame" x="5" y="224" width="365" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand All @@ -41,18 +42,26 @@
<constraint firstItem="Opb-BT-xiP" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="5" id="1CU-Pe-kBU"/>
<constraint firstItem="hoj-tc-K51" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="3uf-GC-Yeu"/>
<constraint firstItem="hoj-tc-K51" firstAttribute="top" secondItem="EJ7-Y2-nrO" secondAttribute="bottom" constant="10" id="5jE-i2-2GZ"/>
<constraint firstAttribute="trailing" secondItem="LKB-aH-scG" secondAttribute="trailing" id="780-if-Dfu"/>
<constraint firstAttribute="bottom" secondItem="LKB-aH-scG" secondAttribute="bottom" id="9bX-bI-jUD"/>
<constraint firstAttribute="trailing" secondItem="EJ7-Y2-nrO" secondAttribute="trailing" constant="5" id="B60-mb-6NP"/>
<constraint firstItem="EJ7-Y2-nrO" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="5" id="HYz-iO-1sm"/>
<constraint firstItem="EJ7-Y2-nrO" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="5" id="Ig4-Aj-mWl"/>
<constraint firstItem="Opb-BT-xiP" firstAttribute="top" secondItem="hoj-tc-K51" secondAttribute="bottom" constant="10" id="VYt-oI-EN1"/>
<constraint firstAttribute="trailing" secondItem="Opb-BT-xiP" secondAttribute="trailing" constant="5" id="WYZ-v6-Hph"/>
</constraints>
<connections>
<outlet property="adChoicesView" destination="LKB-aH-scG" id="MGW-7S-4ph"/>
<outlet property="captionView" destination="Opb-BT-xiP" id="hSg-rU-Z7U"/>
<outlet property="headlineView" destination="EJ7-Y2-nrO" id="BKi-kL-8EA"/>
<outlet property="mainPlaceholder" destination="hoj-tc-K51" id="pmf-nl-x4R"/>
</connections>
<point key="canvasLocation" x="20.800000000000001" y="24.287856071964018"/>
</view>
</objects>
<resources>
<systemColor name="darkTextColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@property(nonatomic, weak) IBOutlet UILabel *headlineView;
@property(nonatomic, weak) IBOutlet UIView *mainPlaceholder;
@property(nonatomic, weak) IBOutlet UILabel *captionView;
@property(nonatomic, weak) IBOutlet UIImageView *adChoicesView;

/// Populates the ad view with the custom native ad object.
- (void)populateWithCustomNativeAd:(GADCustomNativeAd *)customNativeAd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,34 @@ - (void)awakeFromNib {
// Enable clicks on the headline.
[self.headlineView addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(performClickOnHeadline)]];
action:@selector(performClickOnHeadline:)]];
self.headlineView.userInteractionEnabled = YES;

// Enable clicks on AdChoices.
[self.adChoicesView addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(performClickOnAdChoices:)]];
self.adChoicesView.userInteractionEnabled = YES;
}

- (void)performClickOnHeadline {
- (void)performClickOnHeadline:(UITapGestureRecognizer *)sender {
[self.customNativeAd performClickOnAssetWithKey:MySimpleNativeAdViewHeadlineKey];
}

- (void)performClickOnAdChoices:(UITapGestureRecognizer *)sender {
[self.customNativeAd performClickOnAssetWithKey:GADNativeAdChoicesViewAsset];
}

- (void)populateWithCustomNativeAd:(GADCustomNativeAd *)customNativeAd {
self.customNativeAd = customNativeAd;

// Render the AdChoices image.
GADNativeAdImage *adChoicesAsset = [customNativeAd imageForKey:GADNativeAdChoicesViewAsset];
if (adChoicesAsset) {
self.adChoicesView.image = adChoicesAsset.image;
}
self.adChoicesView.hidden = (adChoicesAsset == nil);

// The custom click handler is an optional block which will override the normal click action
// defined by the ad. Pass nil for the click handler to let the SDK process the default click
// action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#import "MySimpleNativeAdView.h"

static NSString *const TestAdUnit = @"/6499/example/native";
static NSString *const TestNativeCustomTemplateID = @"10104090";
static NSString *const TestNativeCustomTemplateID = @"10063170";

@interface ViewController () <GADAdLoaderDelegate,
GADCustomNativeAdLoaderDelegate,
Expand Down

0 comments on commit f2661bc

Please sign in to comment.