开发者

Draw points in a view on iPhone screen?

开发者 https://www.devze.com 2022-12-30 05:19 出处:网络
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\"];

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"];

But how can 开发者_运维百科I do to draw some points with coordinate x, y (in pixel) directly in the view ?

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消