我似乎无法打印我的第二个UILabel,但第一个打印出来。任何帮助表示赞赏。
我正在尝试在蓝色uiview上打印黄色标签,就像我已成功完成红色标签一样。
这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
CGRect frame = CGRectMake(10, 30, 100, 100);
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
UILabel *myLabel2= [[UILabel alloc] initWithFrame:frame];
myLabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
myLabel.backgroundColor = [UIColor redColor];
myLabel.text = @"Hello";
myLabel2=[[UILabel alloc] initWithFrame:CGRectMake(50,300,100,100)];
myLabel2.backgroundColor=[UIColor yellowColor];
myLabel2.text=@"World!";
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(1, 1, 500, 500)];
UIView *myView1 = [[UIView alloc] initWithFrame:CGRectMake(65,50,200,200)];
UIView *myView2= [[UIView alloc] initWithFrame:CGRectMake(65,260,200,200)];
myView1.backgroundColor=[UIColor greenColor];
myView.backgroundColor=[UIColor cyanColor];
myView2.backgroundColor=[UIColor blueColor];
[myView addSubview:myView1];
[myView addSubview:myView2];
[myView2 addSubview:myLabel2];
[myView1 addSubview:myLabel];
[self.window addSubview:myView];
[self.window makeKeyAndVisible];
return YES;
}
感谢您的帮助。
答案 0 :(得分:0)
更改此行
myLabel2=[[UILabel alloc] initWithFrame:CGRectMake(50,300,100,100)];
到
myLabel2=[[UILabel alloc] initWithFrame:CGRectMake(50,30,100,100)];
原因是您的label2
超出了您的观点
希望这可以帮助你..
答案 1 :(得分:0)
“实际上你的标签已被绘制到myView2的视图区域之外。”
myView2的宽度和高度为200,200
myLabel2的y位置为300,超过了superView(myView2)的高度。
:)。
myLabel2是在myView2框架之外绘制的。始终y视图的位置相对于其超视图。