> For the complete documentation index, see [llms.txt](https://docs.adx3.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adx3.io/copy-of-cn/jie-kou-wen-dang/ios/guang-gao-ge-shi/heng-fu-guang-gao.md).

# 横幅广告

横幅广告会占据应用布局中的一处位置。这类广告会在用户和应用互动时停留在屏幕上，并且可在一段时间后自动刷新。

## 前提条件

* 通读[入门指南](/copy-of-cn/jie-kou-wen-dang/ios/kai-shi/ru-men-zhi-nan.md)。

## 务必用测试广告进行测试

在构建和测试应用时，请确保使用的是测试广告，而不是实际投放的广告。否则，能会导致您的账号被暂停使用。

对于横幅广告，使用下面的专用测试广告单元 ID&#x20;

```
63a573861ac5f
```

该测试广告单元 ID 已经过专门配置，可确保每个请求返回的都是测试广告。您可以在自己应用的编码、测试和调试过程中随意使用该测试广告单元 ID。需要注意的一点是，请务必在发布应用前用您的广告单元 ID 替换该测试广告单元 ID。

## 创建 Adx3BannerAdView&#x20;

横幅广告在 Adx3BannerAdView 中展示，您可以将 Adx3BannerAdView 添加到 storyboard 或 xib 文件中，使用此方法时，请务必添加宽度和高度限制，以匹配您要展示的广告尺寸。例如，当展示 320x50 的横幅广告时，请使用 320 点的宽度限制和 50 点的高度限制。

代码方式集成

您还可以直接将 Adx3BannerAdView 实例化。以下示例展示了如何创建 Adx3BannerAdView，使之贴靠至屏幕安全区域底部的中央位置，并使用 250x150 的横幅广告尺寸：

{% tabs %}
{% tab title="Swift" %}

```swift
class ViewController: UIViewController {
    
    var bannerView : Adx3BannerAdView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.addBannerView()
        // Do any additional setup after loading the view.
    }
    
    func addBannerView() {
        bannerView = Adx3BannerAdView.init(adSize: CGSize(width: 250, height: 150), delegate: self)
        bannerView!.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(bannerView)
        view.addConstraint(NSLayoutConstraint.init(item: bannerView!, attribute: .bottom, relatedBy: .equal, toItem: bottomLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0.0))
        view.addConstraint(NSLayoutConstraint.init(item: bannerView!, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0.0))
    }

}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
#import "Adx3Framework/Adx3Ad.h"

@interface ViewController ()

@property (strong, nonatomic) Adx3BannerAdView *bannberView;

@end

@implementation ViewController

- (void)viewDidLoad {
        [super viewDidLoad];
        [self addBannerView];
}

- (void)addBannerView {
        CGSize adSize = CGSizeMake(250, 150);
        [self.bannberView removeFromSuperview];
        self.bannberView = [[Adx3BannerAdView alloc] initWithAdSize:adSize delegate:self];
        self.bannberView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.view addSubview:self.bannberView];
        [self.view addConstraints:
            @[[NSLayoutConstraint constraintWithItem:self.bannberView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0],
              [NSLayoutConstraint constraintWithItem:self.bannberView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]
        ]];
}

@end
```

{% endtab %}
{% endtabs %}

## 加载广告

在 Adx3BannerAdView 创建完成后，就可以加载广告了，示例：

{% tabs %}
{% tab title="Swift" %}

```swift
 //userId Optional
 self.bannerView.loadRequest(withPlacementID: "Your Placement ID", userId: "", delegate: self)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
// userId optional
[self.bannberView loadRequestWithPlacementID:@"Your Placement ID" userId:@"" delegate:self];
```

{% endtab %}
{% endtabs %}

## 广告事件

通过实现 Adx3BannerDelegate 中的方法（可选），您可以监听广告点击事件，示例：

{% tabs %}
{% tab title="Swift" %}

```swift
func bannerDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
    print("----banner did click----")
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
-(void)bannerDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
    NSLog(@"----banner did click----");
}
```

{% endtab %}
{% endtabs %}
