1

在我的appDelegate.m我有这段代码,但UILabel没有显示,而只有UIImageView.

为什么?

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];
4

2 回答 2

5

notificationLabel 是 notificationView 的子视图。它被放置在其超级视图的范围之外。

尝试

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

然后从那里去。对于所有子视图,超级视图的左上角为 (0, 0)。

于 2012-06-27T16:20:21.890 回答
4

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

于 2012-06-27T16:06:37.140 回答