in my class I have an attribute IBOutlet UIImageView *imageView;
And if I want to draw an image in this view I do : imageView.image = [UIImage imageNamed:@"foo.png"];
Thanks !
UIImageView isn't designed to allow arbitrary drawing code. For this purpose, use a UIView and override the drawRect:
method.
After you follow Marcelo's suggestion to draw in the view, you can pull the uiimage from the view with something like:
+(UIImage *)grabImageFromView: (UIView *) viewToGrab {
UIGraphicsBeginImageContext(viewToGrab.bounds.size);
[[viewToGrab layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
精彩评论