การใช้โฆษณาเนทีฟช่วยให้คุณปรับแต่งโฆษณาได้ ซึ่งจะส่งผลให้ผู้ใช้ได้รับประสบการณ์การใช้งานที่ดีขึ้น
ประสบการณ์การใช้งานที่ดีขึ้นของผู้ใช้สามารถเพิ่มการมีส่วนร่วมและปรับปรุงผลตอบแทนโดยรวม
เพื่อให้ได้รับประโยชน์สูงสุดจากโฆษณาเนทีฟ คุณควรจัดรูปแบบเลย์เอาต์โฆษณาให้ดูเหมือนเป็นส่วนขยายตามธรรมชาติของแอป เราได้สร้างเทมเพลตโฆษณาเนทีฟขึ้นมาเพื่อช่วยคุณเริ่มต้นใช้งาน
เทมเพลตโฆษณาเนทีฟเป็นมุมมองที่สมบูรณ์ด้วยโค้ดสำหรับโฆษณาเนทีฟ ซึ่งออกแบบมาเพื่อให้ติดตั้งใช้งานได้อย่างรวดเร็วและแก้ไขได้ง่าย เทมเพลตโฆษณาเนทีฟช่วยให้คุณติดตั้งใช้งานโฆษณาเนทีฟรายการแรกได้ในเวลาเพียงไม่กี่นาที และปรับแต่งรูปลักษณ์ได้อย่างรวดเร็วโดยไม่ต้องใช้โค้ดจำนวนมาก คุณสามารถวางเทมเพลตเหล่านี้ไว้ที่ใดก็ได้ที่ต้องการ เช่น ใน TableView ที่ใช้ในฟีดข่าว ในกล่องโต้ตอบ หรือที่อื่นๆ ในแอป
คู่มือนี้จะแสดงวิธีดาวน์โหลด รวม และใช้เทมเพลตโฆษณาเนทีฟในแอป iOS โดยจะถือว่าคุณใช้ SDK เพื่อโหลดโฆษณาเนทีฟได้สำเร็จแล้ว
ขนาดเทมเพลต
เทมเพลตมี 2 ขนาด ได้แก่ เล็กและกลาง เทมเพลตแต่ละรายการแสดงด้วยคลาส คลาสคือ GADTSmallTemplateView และ GADTMediumTemplateView ทั้ง 2 คลาสขยาย GADTTemplateView เทมเพลตทั้ง 2 รายการมีอัตราส่วนกว้างยาวคงที่ ซึ่งจะปรับขนาดให้พอดีกับความกว้างของมุมมองหลักก็ต่อเมื่อคุณเรียกใช้ addHorizontalConstraintsToSuperviewWidth
หากไม่เรียกใช้ addHorizontalConstraintsToSuperviewWidth เทมเพลตแต่ละรายการจะแสดงผลตามขนาดเริ่มต้น
GADTSmallTemplateView
เทมเพลตขนาดเล็กเหมาะสำหรับเซลล์ UICollectionView หรือ UITableView เช่น คุณสามารถใช้เทมเพลตนี้สำหรับโฆษณาในฟีด หรือที่ใดก็ตามที่คุณต้องการมุมมองโฆษณาสี่เหลี่ยมผืนผ้าแบบบาง ขนาดเริ่มต้นของเทมเพลตนี้คือสูง 91 จุด กว้าง 355 จุด

GADTMediumTemplateView
เทมเพลตขนาดกลางออกแบบมาให้เป็นมุมมอง 1/2 ถึง 3/4 ของหน้า เทมเพลตนี้เหมาะสำหรับหน้า Landing Page หรือหน้า Splash แต่ยังสามารถรวมไว้ใน UITableViews ได้ด้วย ขนาดเริ่มต้นของเทมเพลตนี้คือสูง 370 จุด กว้าง 355 จุด

เทมเพลตทั้งหมดของเรารองรับการจัดวางอัตโนมัติ คุณจึงสามารถทดลองวางตำแหน่งต่างๆ ได้ตามต้องการ แน่นอนว่าคุณยังสามารถเปลี่ยนซอร์สโค้ดและไฟล์ xib ให้เหมาะกับความต้องการได้ด้วย
การติดตั้งเทมเพลตโฆษณาเนทีฟ
หากต้องการติดตั้งเทมเพลตโฆษณาเนทีฟ เพียงดาวน์โหลดไฟล์ zip แล้วลากลงในโปรเจ็กต์ Xcode ตรวจสอบว่าได้เลือกคัดลอกรายการหากจำเป็น

การใช้เทมเพลตโฆษณาเนทีฟ
เมื่อเพิ่มโฟลเดอร์ลงในโปรเจ็กต์และรวมคลาสที่เกี่ยวข้องไว้ในไฟล์แล้ว ให้ทำตามสูตรนี้เพื่อใช้เทมเพลต โปรดทราบว่าวิธีเดียวที่จะเปลี่ยนพร็อพเพอร์ตี้แบบอักษรและสไตล์คือการใช้พจนานุกรมสไตล์ ปัจจุบันเราจะลบล้างสไตล์ที่ตั้งไว้ใน xib เอง
Objective-C
/// Step 1: Import the templates that you need. #import "NativeTemplates/GADTSmallTemplateView.h" #import "NativeTemplates/GADTTemplateView.h" ... // STEP 2: Initialize your template view object. GADTSmallTemplateView *templateView = [[NSBundle mainBundle] loadNibNamed:@"GADTSmallTemplateView" owner:nil options:nil] .firstObject; // STEP 3: Template views are just GADNativeAdViews. _nativeAdView = templateView; nativeAd.delegate = self; // STEP 4: Add your template as a subview of whichever view you'd like. // This must be done before calling addHorizontalConstraintsToSuperviewWidth. // Please note: Our template objects are subclasses of GADNativeAdView so // you can insert them into whatever type of view you’d like, and don’t need to // create your own. [self.view addSubview:templateView]; // STEP 5 (Optional): Create your styles dictionary. Set your styles dictionary // on the template property. A default dictionary is created for you if you do // not set this. Note - templates do not currently respect style changes in the // xib. NSString *myBlueColor = @"#5C84F0"; NSDictionary *styles = @{ GADTNativeTemplateStyleKeyCallToActionFont : [UIFont systemFontOfSize:15.0], GADTNativeTemplateStyleKeyCallToActionFontColor : UIColor.whiteColor, GADTNativeTemplateStyleKeyCallToActionBackgroundColor : [GADTTemplateView colorFromHexString:myBlueColor], GADTNativeTemplateStyleKeySecondaryFont : [UIFont systemFontOfSize:15.0], GADTNativeTemplateStyleKeySecondaryFontColor : UIColor.grayColor, GADTNativeTemplateStyleKeySecondaryBackgroundColor : UIColor.whiteColor, GADTNativeTemplateStyleKeyPrimaryFont : [UIFont systemFontOfSize:15.0], GADTNativeTemplateStyleKeyPrimaryFontColor : UIColor.blackColor, GADTNativeTemplateStyleKeyPrimaryBackgroundColor : UIColor.whiteColor, GADTNativeTemplateStyleKeyTertiaryFont : [UIFont systemFontOfSize:15.0], GADTNativeTemplateStyleKeyTertiaryFontColor : UIColor.grayColor, GADTNativeTemplateStyleKeyTertiaryBackgroundColor : UIColor.whiteColor, GADTNativeTemplateStyleKeyMainBackgroundColor : UIColor.whiteColor, GADTNativeTemplateStyleKeyCornerRadius : [NSNumber numberWithFloat:7.0], }; templateView.styles = styles; // STEP 6: Set the ad for your template to render. templateView.nativeAd = nativeAd; // STEP 7 (Optional): If you'd like your template view to span the width of your // superview call this method. [templateView addHorizontalConstraintsToSuperviewWidth]; [templateView addVerticalCenterConstraintToSuperview];
คีย์พจนานุกรมสไตล์
วิธีที่เร็วที่สุดในการปรับแต่งเทมเพลตคือการสร้างพจนานุกรมที่มีคีย์ต่อไปนี้
Objective-C
/// Call to action font. Expects a UIFont. GADTNativeTemplateStyleKeyCallToActionFont /// Call to action font color. Expects a UIColor. GADTNativeTemplateStyleKeyCallToActionFontColor; /// Call to action background color. Expects a UIColor. GADTNativeTemplateStyleKeyCallToActionBackgroundColor; /// The font, font color and background color for the first row of text in the /// template. /// All templates have a primary text area which is populated by the native ad's /// headline. /// Primary text font. Expects a UIFont. GADTNativeTemplateStyleKeyPrimaryFont; /// Primary text font color. Expects a UIFont. GADTNativeTemplateStyleKeyPrimaryFontColor; /// Primary text background color. Expects a UIColor. GADTNativeTemplateStyleKeyPrimaryBackgroundColor; /// The font, font color and background color for the second row of text in the /// template. /// All templates have a secondary text area which is populated either by the /// body of the ad, or by the rating of the app. /// Secondary text font. Expects a UIFont. GADTNativeTemplateStyleKeySecondaryFont; /// Secondary text font color. Expects a UIColor. GADTNativeTemplateStyleKeySecondaryFontColor; /// Secondary text background color. Expects a UIColor. GADTNativeTemplateStyleKeySecondaryBackgroundColor; /// The font, font color and background color for the third row of text in the /// template. The third row is used to display store name or the default /// tertiary text. /// Tertiary text font. Expects a UIFont. GADTNativeTemplateStyleKeyTertiaryFont; /// Tertiary text font color. Expects a UIColor. GADTNativeTemplateStyleKeyTertiaryFontColor; /// Tertiary text background color. Expects a UIColor. GADTNativeTemplateStyleKeyTertiaryBackgroundColor; /// The background color for the bulk of the ad. Expects a UIColor. GADTNativeTemplateStyleKeyMainBackgroundColor; /// The corner rounding radius for the icon view and call to action. Expects an /// NSNumber. GADTNativeTemplateStyleKeyCornerRadius;
คำถามที่พบบ่อย
- ทำไมฉันจึงได้รับข้อยกเว้นเมื่อพยายามสร้างออบเจ็กต์เทมเพลต
- ปัญหานี้อาจเกิดขึ้นหากคุณเปลี่ยนขนาดของมุมมองในไฟล์ xib แต่ไม่ได้เปลี่ยนขนาดของเฟรมที่สร้างขึ้นในเมธอด "setup" ของคลาสย่อย
- ฉันจะปรับแต่งเทมเพลตเหล่านี้เพิ่มเติมได้อย่างไร
- เทมเพลตเหล่านี้เป็นเพียง xib ที่มีออบเจ็กต์มุมมองที่เชื่อมโยง เช่นเดียวกับคลาส xib และคลาสมุมมองที่กำหนดเองอื่นๆ ที่คุณอาจคุ้นเคยจากการพัฒนา iOS หากต้องการสร้างโฆษณาเนทีฟตั้งแต่ต้น โปรดดู คู่มือโฆษณาเนทีฟขั้นสูง
- ทำไมสไตล์ของฉันจึงไม่อัปเดตเมื่อฉันตั้งค่าใน xib
- ปัจจุบันเราจะลบล้างสไตล์ xib ทั้งหมดด้วยพจนานุกรมสไตล์เริ่มต้นใน
GADTTemplateView.m
มีส่วนร่วม
เราได้สร้างเทมเพลตโฆษณาเนทีฟขึ้นมาเพื่อช่วยคุณพัฒนาโฆษณาเนทีฟได้อย่างรวดเร็ว เรายินดีเป็นอย่างยิ่งหากคุณมีส่วนร่วมใน GitHub ของเราเพื่อเพิ่มเทมเพลตหรือฟีเจอร์ใหม่ๆ ส่ง Pull Request มาให้เรา แล้วเราจะตรวจสอบ