การใช้โฆษณาเนทีฟช่วยให้คุณปรับแต่งโฆษณาได้ตามที่ต้องการซึ่งทำให้ผู้ใช้ได้รับประสบการณ์ที่ดีขึ้น ประสบการณ์ของผู้ใช้ที่ดีขึ้นจะช่วยเพิ่มการมีส่วนร่วมและเพิ่มผลตอบแทนโดยรวม
เพื่อให้ได้รับประโยชน์สูงสุดจากโฆษณาเนทีฟ คุณต้องจัดรูปแบบการออกแบบโฆษณาให้เหมือนส่วนขยายที่เป็นธรรมชาติของแอป เราจึงสร้างเทมเพลตเนทีฟไว้เพื่อช่วยคุณเริ่มต้นใช้งาน
เทมเพลตเนทีฟเป็นมุมมองที่ใช้โค้ดได้สมบูรณ์สำหรับโฆษณาเนทีฟ ออกแบบมาเพื่อการใช้งานที่รวดเร็วและแก้ไขได้ง่าย เทมเพลตเนทีฟช่วยให้คุณนำโฆษณาเนทีฟรายการแรกไปใช้งานได้ในไม่กี่นาที ทั้งยังปรับแต่งรูปลักษณ์ได้อย่างรวดเร็วโดยไม่ต้องใช้โค้ดมากมาย คุณสามารถวางเทมเพลตเหล่านี้ได้ทุกที่ที่ต้องการ เช่น ใน TableView ที่ใช้ในฟีดข่าวสาร ในกล่องโต้ตอบ หรือที่อื่นๆ ในแอป
คู่มือนี้จะแสดงวิธีดาวน์โหลด รวม และใช้เทมเพลตเนทีฟในแอป iOS สมมติว่าคุณใช้ SDK เพื่อโหลดโฆษณาเนทีฟสำเร็จแล้ว
ขนาดเทมเพลต
เทมเพลตมี 2 ขนาดคือ เล็กและกลาง แต่ละเทมเพลตจะแสดงเป็น
คลาส ชั้นเรียนได้แก่ GADTSmallTemplateView
และ GADTMediumTemplateView
ทั้ง 2 ชั้นเรียนจะขยายเวลาให้บริการ GADTTemplateView
เทมเพลตทั้ง 2 แบบมีสัดส่วนภาพคงที่ ซึ่งจะปรับขนาดตามความกว้างของมุมมองระดับบนสุดเมื่อคุณเรียกใช้ addHorizontalConstraintsToSuperviewWidth
เท่านั้น
หากไม่เรียกใช้ addHorizontalConstraintsToSuperviewWidth
แต่ละเทมเพลตจะแสดงขนาดเริ่มต้น
GADTSmallTemplateView
เทมเพลตขนาดเล็กเหมาะกับเซลล์ UICollectionView
หรือ UITableView
เซลล์ เช่น คุณสามารถใช้รูปแบบนี้กับโฆษณาในฟีด หรือที่ใดก็ได้ที่ต้องการมุมมองโฆษณาสี่เหลี่ยมผืนผ้าแบบบาง ขนาดเริ่มต้นของเทมเพลตนี้คือ สูง 91 จุด กว้าง 355 จุด
GADTMediumTemplateView
เทมเพลตสื่อควรมีมุมมอง 1/2 ถึง 4/4 หน้า ซึ่งเหมาะสำหรับหน้า Landing Page หรือหน้าแนะนำ แต่ก็รวมอยู่ใน UITableViews
ได้เช่นกัน ขนาดเริ่มต้นของเทมเพลตนี้คือ สูง 370 จุด สูง 355 จุด
เทมเพลตทั้งหมดของเรารองรับการออกแบบอัตโนมัติ คุณจึงลองใช้การวางตำแหน่งได้ตามต้องการ แน่นอนว่าคุณสามารถเปลี่ยนซอร์สโค้ดและไฟล์ xib ให้เหมาะกับความต้องการของคุณได้
การติดตั้งเทมเพลตโฆษณาเนทีฟ
หากต้องการติดตั้งเทมเพลตเนทีฟ เพียงดาวน์โหลดรหัสไปรษณีย์และลากลงในโปรเจ็กต์ 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 แต่ไม่ได้เปลี่ยนขนาดของเฟรมที่สร้างในเมธอด "ตั้งค่า" ของคลาสย่อย
- ฉันจะปรับแต่งเทมเพลตเหล่านี้เพิ่มเติมได้อย่างไร
- เทมเพลตเหล่านี้เป็นเพียง xib ที่มีออบเจ็กต์มุมมองที่เกี่ยวข้องเท่านั้น เช่น คลาส xib และมุมมองที่กำหนดเองอื่นๆ ที่คุณอาจคุ้นเคยจากการพัฒนาบน iOS หากต้องการสร้างโฆษณาเนทีฟตั้งแต่ต้น โปรดดูคู่มือสำหรับโฆษณาเนทีฟขั้นสูง
- เหตุใดรูปแบบของฉันจึงไม่อัปเดตเมื่อตั้งค่าใน xib
- ปัจจุบันเราลบล้างรูปแบบ xib ทั้งหมดตามพจนานุกรมรูปแบบเริ่มต้นใน
GADTTemplateView.m
มีส่วนร่วม
เราได้สร้างเทมเพลตเนทีฟเพื่อช่วยให้คุณพัฒนาโฆษณาเนทีฟได้อย่างรวดเร็ว เราอยากเห็นคุณมีส่วนร่วมในที่เก็บ GitHub ของเราเพื่อเพิ่มเทมเพลตหรือฟีเจอร์ใหม่ๆ ส่งคำขอพุลถึงเรา แล้วเราจะตรวจสอบให้