2012-06-27 74 views
0

在我的appDelegate.m我有此代码,但UILabel不显示,但只有UIImageView为什么UILabel不显示?

为什么?

notificationView = [[UIImageView alloc] initWithFrame: CGRectMake(154, 320, 140, 47)]; 
notificationView.image = [UIImage imageNamed:@"notification.png"]; 

NSString *message = [NSString stringWithString:@"New Videos"]; 

notificationLabel = [[UILabel alloc] initWithFrame: CGRectMake(165, 313, 140, 47)]; 
notificationLabel.font = [UIFont boldSystemFontOfSize:12]; 
notificationLabel.textAlignment = UITextAlignmentLeft; 
notificationLabel.text = [NSString stringWithFormat:@"%d %@", numberOfVideos, message]; 
notificationLabel.textColor = [UIColor whiteColor]; 
notificationLabel.backgroundColor = [UIColor clearColor]; 

notificationView.alpha = 0.0; 
notificationLabel.alpha = 0.0; 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.5]; 
notificationView.alpha = 1.0; 
notificationLabel.alpha = 1.0; 
[UIView commitAnimations]; 

[self.window addSubview: notificationView]; 
[self.notificationView addSubview: notificationLabel]; 

[UIView commitAnimations]; 

[notificationView release]; 
[notificationLabel release]; 
+0

是你的通知查看(图片)正在显示 – Abhishek

+0

是的,它显示了。 – Winston

+0

检查你的标签的imageView和X轴的宽度 – Abhishek

回答

5

notificationLabel是notificationView的子视图。 它超出了它的超视界。

尝试

notificationLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 140, 47)]; 

,并从那里走。对于所有子视图,超级视图的左上角是(0,0)。

+0

仍然没有显示标签。 – Winston

+0

现在它工作正常。感谢您的CGRectMake(0,0,140,47)提示! – Winston

4

通知视图的宽度是140。您的标签被放置在通知视图的165的X位置,该通知视图超出了通知视图的范围。所以它不可见。

+0

我已经在CGRectMake(154,320,165,47)中设置了UIImageView和UILabel,但仍然没有UILabel显示。 – Winston