ContainerView隐藏UILabel

时间:2011-07-29 06:58:53

标签: iphone xcode4 uilabel

我想在ContainerView中使用UILabel 所以我正在使用这个代码。

UILabel *myLabel = [[[UILabel alloc] initWithFrame:CGRectMake(16, 60, 300, 150)] autorelease];
myLabel.numberOfLines = 0;
myLabel.font = [UIFont systemFontOfSize:13.5];
myLabel.text = [theQuiz objectAtIndex:row+3] ;
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.layer.cornerRadius = 8.0;
[myLabel sizeToFit];
[self.view addSubview:myLabel];

//ContainerView
UIView *ChallengeView = [[UIView alloc] initWithFrame:CGRectMake(8, 55, 300, 10 + Challenge.frame.size.height)];
ChallengeView.layer.borderColor = [[UIColor purpleColor ] CGColor];
[ChallengeView setBackgroundColor:[UIColor whiteColor]];
ChallengeView.layer.cornerRadius = 8 ;
ChallengeView.layer.borderWidth = 1.5;
[self.view addSubview:ChallengeView];
[ChallengeView release];

现在的问题是,当我为ContainerView设置背景颜色时,它会隐藏 myLabel 的文本

任何解决方案?

2 个答案:

答案 0 :(得分:0)

正在发生的事情是,您在containerView之后添加了containerView,或者在containerView之后添加标签或执行此操作:

[self.view bringSubviewToFront:myLabel];

答案 1 :(得分:0)

首先添加ChallengeView,然后添加myLabel。 否则你可以像@ xs2bush那样做,

[self.view bringSubviewToFront:myLabel];

Bcz ChallengeView隐藏了标签。