设置整个iPhone / iPad应用程序的背景图像

时间:2011-02-06 19:14:45

标签: iphone objective-c ipad

我想要一个单独的图片作为我的应用程序的背景,无论他们在哪个viewcontroller上 - 你如何实现这一目标?

8 个答案:

答案 0 :(得分:91)

以下是为图像设置背景的方法:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

编辑:要写下Felixyz所说的内容(感谢Manni),请在您的代表中执行此操作:

window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

在每个视图中,您想拥有图片,请执行以下操作:

self.view.backgroundColor = [UIColor clearColor];

答案 1 :(得分:8)

取决于您拥有的界面类型。分页?导航基础?但一般的答案是:在主视图之前/之下向UIWindow添加UIImageView。然后使主视图控制器处理的每个视图都具有透明背景。很难提供更具体的建议,而不知道你是否使用IB,或者你的视图层次结构是什么样的。

答案 2 :(得分:7)

在我的应用中,我设置了默认背景颜色。也许你可以用你的背景图片做到这一点:

1。:在AppDelegate中设置UIWindow的背景颜色:

window.backgroundColor = [UIColor myBackgroundGray]; // own Category

2:现在,让所有其他观点透明:

self.view.backgroundColor = [UIColor clearColor]; // = transparent

答案 3 :(得分:7)

在你的AppDelegate中

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

添加以下行:

[self.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

您必须将观看背景设置为[UIColor clearColor];

答案 4 :(得分:3)

我不确定性能的影响,但我需要完成类似的事情,最后使用的UIImageView运行良好(在C#中,但在obj-c中的工作方式相同):

//Add the view controller first, to ensure proper order of views later.
Window.RootViewController = new UIViewController();

//create backdrop image view
var imageView = new UIImageView(Window.Bounds);
imageView.Image = UIImage.FromBundle("backdrop.jpg");

//insert into window.
Window.InsertSubview(imageView, 0);

这不会处理方向更改,但在我的情况下,允许我向背景添加动态效果(例如视差)。

答案 5 :(得分:2)

您的背景是任何View继承对象的属性。例如,标签,按钮,控制器和应用程序窗口都具有背景。如果你希望它完全是整个应用程序的bg,你必须爬上你的控制器中的路径,找到非常“顶部”(底部查看)的视图,并将其背景设置为你想要的图像。

答案 6 :(得分:1)

只需在\Log::info("Message here");

中调用此public function getLogout() { \Log::info('User has logged out.', ['email' => \Auth::user()->email]); \Auth::logout(); return redirect('/'); } 即可
assignbackground

答案 7 :(得分:0)

我通常使用此功能来避免与iPhone上的导航栏重叠。

import pylab as plt
import numpy as np
import scipy

numsamples=1000
f0=1/10
x=np.linspace(0,100,numsamples)
y=np.sin(2*np.pi*f0*x)
fs=numsamples/(max(x)-min(x))
nyquist=0.5*fs
fstart=(3/4)*f0/nyquist
fstop=(4/3)*f0/nyquist
a,b  = scipy.signal.butter(2,[fstart,fstop],'bandstop', analog=True)
fy = scipy.signal.lfilter(a,b,y, axis=-1, zi=None)
plt.plot(y)
plt.plot(fy)
plt.show()