这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
int rand2 = arc4random() % 5;
switch (rand2) {
case 0:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pinkfont.png"]];
break;
case 1:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"greenfont.png"]];
break;
case 2:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"whitefont.png"]];
break;
case 3:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellowfont.png"]];
break;
case 4:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"purplefont.png"]];
break;
}
[[[self view] layer] addSublayer:[imgView layer]];
[imgView release];
}
我想将imgView放在后台,但它不起作用,我尝试使用界面生成器“发送回”但没有结果。我该怎么解决这个问题呢?
对不起我的英语我是法国人:)
答案 0 :(得分:0)
你可以这样做:
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];
检查此代码后,您没有在viewWillAppear中添加其他视图,如果添加其他视图,请再次发送子视图。
答案 1 :(得分:0)
在viewwillappear方法的末尾写下这行代码。
[self.view sendSubviewToBack:imgView];
答案 2 :(得分:0)
如果您有xib文件,则在xib文件中拖动图像视图,然后从菜单选项卡中选择布局并选择向后或向后发送。 或者你必须动态创建然后写
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.png"]];
答案 3 :(得分:0)
将图像设置为视图背景使用此
UIImage *img = [UIImage imageNamed:@"pinkfont.png"]
[self.view setBackgroundColor:[UIColor colorWithPatternImage:img]];