如何正确插入背景图像

时间:2011-08-05 02:32:23

标签: iphone ios ipad subview layer

我使用此代码设置背景图片。唯一的问题是它涵盖了我在XIB文件中插入的所有内容。我该怎么做才能确保我的文本字段,按钮等也可见(在背景前面)。谢谢你的帮助!

// Setup the background
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:background];
[background release];

2 个答案:

答案 0 :(得分:1)

  

UIImageView * background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@“background.png”]];       [self.view addSubview:background];   [self sendSubviewToBack:background];       [背景发布];

答案 1 :(得分:0)

如果您使用的是XIB,请确保所有对象都在UIImageView之上。

或者,您可以使用colorWithPatternImage:

UIImage * bg = [UIImage imageNamed:@"bg.png"];
[myView_ setBackgroundColor:[UIColor colorWithPatternImage: bg]];
相关问题