Adding a shortcut to an application window from a delegate application

I use Xcode 4.5 and iOS 6.0, I selected the default single view template from xcode, I just want to add a shortcut to the application window, but I cannot do this. Please correct me.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)]; label.text = @"Test"; [label setBackgroundColor:[UIColor whiteColor]]; [self.window addSubview:label]; [self.window bringSubviewToFront:label]; [self.window makeKeyAndVisible]; return YES; } 

PS - I want my shortcut to be on top of my ViewController, for example, in a window, so it will always be there, despite the changes in the views presented by the window. I do not want to show only the shortcut.

I got an answer

 [self.window.rootViewController.view addSubview:label]; 

Thanks to everyone for providing pointers.

+4
source share
2 answers

Just uninstall RootviewController .

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)]; label.text = @"Test"; [label setBackgroundColor:[UIColor whiteColor]]; [self.window addSubview:label]; [self.window bringSubviewToFront:label]; [self.window makeKeyAndVisible]; return YES; } 

if you do not want to show only the label here, use as shown below.

 self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.Viewcontroller.view addSubview:label]; 
+4
source

Add a shortcut to self.window.rootViewController.view instead of self.window

 UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)]; label.text = @"Test"; [label setBackgroundColor:[UIColor whiteColor]]; [self.window.rootViewController.view addSubview:label]; 
+3
source

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


All Articles