I am developing a paint application using OpenGL.
I am using "CUSTOM UIView" for drawing on a screen and another UIImageView to set background image to it. Have a look at screenshot to understand it clearly.. My problem is I am not able to set background image on either of the view.. I have to use different textures as a drawing board on which I have to Paint. Can anyone suggest what is incorrect in this approach??
I have used this code for custom UIView but not getting success.. but it shows white default background only..
- (id)initWithCoder:(NSCoder*)coder {
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Rough_White_Paper_with_tape.png"]];
self.backgroundColor = background;
[background release]; 开发者_JAVA技巧
}
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];
use this
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default"]];
- (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...
Try this:
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Rough_White_Paper_with_tape.png"]];
[self addSubview:background];
[self sendSubviewToBack:background];
[background release];
Try this:
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed :@“abc.png"]];
UIView *myUIView = [[UIImageView alloc] initWithFrame :CGRectMake(10,10,250,250)];
myUIView = myImageView;
set background with UIImageView is not graceful。 should use following API:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];
this is in swift 2
var background = UIImageView(image: UIImage(named: "image.jpg"))
self.addSubview(background)
self.sendSubviewToBack(background)
Use this
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"image.png"]];
精彩评论