在我的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];
答案 0 :(得分:5)
notificationLabel是notificationView的子视图。 它被置于超级视图范围之外。
尝试
notificationLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 140, 47)];
从那里开始。对于所有子视图,超级视图的左上角是(0,0)。
答案 1 :(得分:4)
通知视图的宽度为140
。您的标签位于通知视图中的165
的X位置,该位置超出了通知视图的范围。所以它不可见。