[英]Setting a global background image or color in iOS
以下代碼有問題。
1.)我想要達到的目標; -在iOS的AppDelegate中顯示全局背景圖像或顏色
2.)發生了什么事; -顯示的圖像或顏色表明代碼正常運行,因為未發生任何錯誤或警告。
3.)問題是什么; -背景顏色或圖像幾乎占據了整個屏幕,就像它是最頂層一樣,因此我看不到uitext,button等元素。只是背景圖像..好,因為它工作不好,因為...用戶可以使用該應用程序!
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;
}
有任何想法嗎?
問候,傑里米
我使用常見的隨附文件中的UIViewController類別解決了相同的問題。 因此,每個UIviewController的init函數都調用[self setMyColor]。
這是我的代碼:
@interface ColorViewController : UIViewController
- (void) setMyColor;
@end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.