Cocoa touch / Xcode - create a graphical context without using NIB

My application delegate contains:

- (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; if (!window) { [self release]; return; } window.backgroundColor = [UIColor greenColor]; [window addSubview:viewController.view]; [window makeKeyAndVisible]; [window layoutSubviews]; } 

This seems to be done without errors. The window variable is NOT 0 , so the if (! window) Window 0 test does not return a function. However, a window with a green background is not displayed, but only the default color. And in the appController.m file, the code in the viewDidLoad method is executed. However, CGContextRef context = UIGraphicsGetCurrentContext(); returns null, not the real context.

What am I leaving?

+1
source share
1 answer

I suspect that your window is not green, because the view added with [window addSubview:viewController.view]; is opaque and covers the entire window.

As for the other problem, if you are requesting the current graphics context in viewDidLoad , I do not think that one thing is guaranteed. You can only draw UIViews by subclassing and overriding their drawRect:(CGRect) method. If you want to do this outside of this, you need to create your own graphical context using CGBitmapContextCreate , and then display the results either by drawing them as drawRect: or by finding another control that will accept the CGImage that you made using the raster functions ( i.e. UIImage ).

+3
source

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


All Articles