Set background Image for a Custom UIView
NSURL *imgUrl=[[NSURL alloc] initWithString:@"http://img835.imageshack.us/img835/9794/screenshot20110802at345.png"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
imageView = [[UIImageView alloc] initWithImage:img];
[self addSubview:imageView ];
[self sendSubviewToBack:imageView ];
[imageView release]; [imgUrl release];
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Rough_White_Paper_with_tape.png"]];
self.backgroundColor = background;
[background release];
}
return self;
}
You just had to add return self; It works perfectly fine for me...
use this
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default"]];
Try this:
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Rough_White_Paper_with_tape.png"]];
[self addSubview:background];
[self sendSubviewToBack:background];
[background release];