Get context from UIImageView

Is it possible to get context ( CGContextRef) from an existing one UIImageView?

Details: I have a link for the controller to the xib file. In IB, I added UIImageViewand refer to:

IBOutlet UIImageView *imageView;

Now, in viewDidLoadHow to get context UIImageView( CGContextRef)?

Prior to this, if I use:

CGContextRef context = UIGraphicsGetCurrentContext();

exit:

<Error>: CGContextTranslateCTM: invalid context

are you suggesting?

+3
source share
2 answers

, drawRect: UIView. UIView . XCode File- > New File UIView , . Interface-Builder , Identity Inspector.

- , :

- (void)drawRect:(CGRect)fr {
    CGContextRef context = UIGraphicsGetCurrentContext();
    ... DRAWING CODE ...
}

. , setNeedsDisplay UIView, .

UIImageView (LINK):

UIImageView . UIImageView drawRect: . , UIView .

+3

UIGraphicsBeginImageContext (self.frame.size); UIGraphicsGetCurrentContext();   .

 UIGraphicsBeginImageContext(self.frame.size); 
 CGContextRef context = UIGraphicsGetCurrentContext();
+2

Source: https://habr.com/ru/post/1723051/


All Articles