Here is my code :
- (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] initWith开发者_运维问答Image:[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];
}
I want to put imgView at the background, but it doesn't work, I tried to do it with interface Builder with "send to back" but no result. How can I solve this please?
Sorry for my english I'm french :)
if you have xib file then drag a image view in your xib file and then from menu tab select layoutand choose sent to back or backward. or you have to create dynamically then write
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.png"]];
you can do:
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];
Check after this code, you are not adding other views in viewWillAppear, if you add other views, send subview to back again.
write this line of code at the end of your viewwillappear method.
[self.view sendSubviewToBack:imgView];
to set image as your view background use this
UIImage *img = [UIImage imageNamed:@"pinkfont.png"]
[self.view setBackgroundColor:[UIColor colorWithPatternImage:img]];
精彩评论