开发者

UIImage from UIView to UIViewController

开发者 https://www.devze.com 2023-01-15 05:25 出处:网络
I am creating a UIImage programmatically in my UIView\'s drawRect function. Is there a way that the UIViewController responsible for this UIView access that image (or开发者_StackOverflow社区 a copy of

I am creating a UIImage programmatically in my UIView's drawRect function. Is there a way that the UIViewController responsible for this UIView access that image (or开发者_StackOverflow社区 a copy of it) for manipulation?

Appreciate any pointers and thanks in advance.


If your UIImage you create programmatically in your drawrect is stored as a property on the UIView subclass, then the UIViewController can access the image.

Obviously, if you are using Interface Builder you'd need to wire up your UIView subclass to an IBOutlet on the UIViewController class to access the property, but I'm sure you're doing that already.

e.g. in the drawrect function

self.storedImage = [[UIImage alloc] init... ];

in the header for the UIView subclass
UIImage* storedImage;

@property (nonatomic, retain) UIImage* storedImage;

The nonatomic retained property ensures that you're not leaking UIImages each time the draw rect function is called.

0

精彩评论

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

关注公众号