【发布时间】:2014-06-05 02:19:52
【问题描述】:
我刚刚开始制作一个带有导航栏的新应用。我在AppDelegate.m 中使用导航制作了第一个视图。
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(2);
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
然后,我在 loadView 方法中制作 HomeViewController 的视图。
HomeViewController 的加载视图:
- (void)loadView
{
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor whiteColor];
self.searchPoiInstructionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
self.searchPoiInstructionsLabel.layer.borderColor = [UIColor blackColor].CGColor;
self.searchPoiInstructionsLabel.layer.borderWidth = 2.0f;
self.searchPoiInstructionsLabel.text = @"HELLO WORLD";
[self.view addSubview:self.searchPoiInstructionsLabel];
}
我的标签 Hello World 没有出现...
对于框架,如果我将CGRectMake(0, 65, 50, 20) ,65 设置为y,我的“Hello World”就会出现...(我知道,我必须增加宽度:))
我只是不明白我的观点的起源......如果有人可以解释我。
谢谢
【问题讨论】:
-
我认为在
viewWillAppear方法中添加您的 CGRectMake 代码应该可以解决您的问题? -
你也可以做 [self.searchPoiInstructionsLabel sizeToFit] 来自动固定宽度。如果您使用情节提要,则需要关闭自动布局。
标签: ios objective-c cgrectmake