从应用程序委托在应用程序窗口上添加标签

编程入门 行业动态 更新时间:2024-10-27 16:35:05
本文介绍了从应用程序委托在应用程序窗口上添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I am using Xcode 4.5 and iOS 6.0, I have selected the default single view template from the xcode, I just want to add the label on the application window but I am unable to do so. 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 - 我希望我的标签在我的 ViewController 视图之上,即在窗口上,所以尽管窗口呈现的视图发生了变化,它仍将始终存在.我不想在这里只显示标签.

PS - I want my label on top of my ViewController view i.e. on the window so it will be always there despite changes in the views presented by window. I dont want to only show the label here.

我得到了答案

[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;
}

如果您不想只在此处显示标签,请使用如下所示.

if you dont want to only show the label here then use like below.

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


[self.Viewcontroller.view addSubview:label];

这篇关于从应用程序委托在应用程序窗口上添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 10:57:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1061401.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   窗口   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!