2012-09-21 108 views
0

我有一個iPad/iPhone應用程序和iPhone背景看起來不錯,但是當我使用iPad版本的相同圖像時,它看起來像是在中間被切斷的頁面。iOS - iPad背景圖像越來越短

這裏是一個屏幕截圖:

enter image description here

的圖像稱爲buildings.png,我有2個版本的吧,buildings.png和建築@ 2個爲iPad。

我得到的圖像中的背景來呈現的方式是這樣的代碼:

- (void)viewDidAppear:(BOOL)animated 
{ 
    UIImage *image = [UIImage imageNamed:@"building"]; 
    self.view.backgroundColor = [UIColor colorWithPatternImage:image]; 

什麼是對我來說,修復圖像的這個問題正在對切斷一樣,最好的辦法iPad視圖?

謝謝!

+0

你檢查你是什麼設備?然後加載適當的圖像? –

+0

@ gerig我實際上並不確定。我認爲它可能不會加載ipad映像。但我不知道如何檢查。 – GeekedOut

+0

如果([[的UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){// 負載iphone圖像 }其他{ //負載ipad的圖像 } –

回答

1

我認爲colorWithPatternImage是你的形象被削減的原因。爲什麼不創建一個UIImageView來包含您的圖像,將其添加到您的視圖,並致電[self.view sendSubviewToBack:yourImageView]

編輯
這裏是您的代碼段

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"building"]]; 
imgView.frame = self.view.bounds; // to set the frame to your view's size 
[self.view addSubview:imgView]; 
[self.view sendSubviewToBack:imgView]; 
+0

嗯有趣。沒有意識到它可能是colorWithPatternImage ....你可以請張貼片段看起來像你的建議?我沒有太多處理圖像的經驗,所以我有點困惑。謝謝! – GeekedOut

+0

我只是試過這個:UIImageView * imgView = [[UIImageView alloc] initWithImage:@「building」]; imgView.frame = self.view.bounds; //將幀設置爲您的視圖的尺寸 [self.view addSubview:imgView]; [self.view sendSubviewToBack:imgView];這並沒有起作用。另外在第一行我得到一個警告,我有不兼容的NSString類型和圖像 – GeekedOut

+0

你必須傳遞一個圖像對象不是一個字符串...我改變我的代碼爲你 – nicolasthenoz