2013-06-22 31 views
2

遇到以下代碼的問題。在iOS中設置全局背景圖像或顏色

1.)我想要達到的目標; - 在iOS的AppDelegate中顯示全局背景圖像或顏色012) - 顯示的圖像或顏色表明代碼正常工作,因爲沒有發生錯誤或警告。

3.)什麼是問題; - 背景顏色或圖像佔據了整個屏幕,就像它是最頂層,因此我看不到任何元素,例如uitext,按鈕等。只是背景圖像...良好,因爲它工作不好,因爲,用戶可以使用應用程序!

4.)我做了什麼; - 下面是我一直在使用的appdelegate中的代碼片段。我知道它在每個UIViewController中都有效,我試圖重構它,所以我只在一個地方使用它。不是200!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

{ 
    //Set the background image 
    if (IDIOM == IPAD) 
    { 
     self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]; 

    } 
    else 
    { 
     //Add gradient background 
     CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient]; 
     bgLayer.frame = self.window.bounds; 
     [self.window.layer insertSublayer:bgLayer atIndex:0]; 

    } 

    //This is added so if in-app purchasing is used and the users connections fails in the middle of the transaction it will finalise the payment so it will download or give access to the purchase. 
    //[ReadingsIAPHelper sharedInstance]; 

    return YES; 
} 

任何想法?

問候, 傑里米

+0

您是否嘗試過的子層發送到回來? – Wain

+0

對不起...還在學習objC ....那會怎麼做? – Jeremy

+0

'[self.window.layer sendSublayerToBack:bgLayer];' – Wain

回答

0

我解決了的UIViewController類同樣的問題是在共同的包含文件。因此,其init函數中的每個UIviewController都會調用[self setMyColor]。

這是我的代碼:

@interface ColorViewController : UIViewController 
    - (void) setMyColor; 
@end