gpt4 book ai didi

objective-c - 从应用程序委托(delegate)在应用程序窗口上添加标签

转载 作者:可可西里 更新时间:2023-11-01 05:23:16 25 4
gpt4 key购买 nike

我正在使用 Xcode 4.5 和 iOS 6.0,我从 xcode 中选择了默认的单一 View 模板,我只想在应用程序窗口上添加标签,但我无法这样做。请指正。

- (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 - 我希望我的标签位于我的 ViewController View 之上,即在窗口上,因此尽管窗口呈现的 View 发生变化,它仍将始终存在。我不想只在这里显示标签。

我得到了答案

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

谢谢大家指点。

最佳答案

只需删除 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;
}

如果您不想只在此处显示标签,请像下面这样使用。

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController"        bundle:nil];
self.window.rootViewController = self.viewController;


[self.Viewcontroller.view addSubview:label];

关于objective-c - 从应用程序委托(delegate)在应用程序窗口上添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com