0
我想設置一個廣告橫幅出現在屏幕上的頂部或底部某處,所以我一直在做的是這樣的;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat screenXPos = (screenWidth /2);
CGFloat screenYPos = screenHeight - 150;
[bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
bannerView_.rootViewController = self;
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
}else{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat screenXPos = (screenWidth /2);
CGFloat screenYPos = screenHeight -480;
[bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
bannerView_.rootViewController = self;
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
這是很凌亂,並沒有真正的工作我怎麼想,比如我想廣告橫幅出現大約150個像素頂掉任何設備(新iPad/iPhone等)
我會更好地在界面構建器中創建橫幅視圖嗎?但是,如果是這樣的話,我將如何實現上述代碼?
在此先感謝!
嗨,這個代碼有一個錯誤,關於screenXPos沒有被聲明 - 也不是我真正在做什麼之後,因爲它基本上和我已經做的一樣......在iPad上150是不夠的,但在iPhone上可以,等等 – user1695971 2013-03-07 23:51:40