2012-06-27 89 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