ContainerView隐藏UILabel

发布于 2024-11-26 19:46:51 字数 967 浏览 2 评论 0原文

我想在 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 的文本

任何解决方案?

I want to use UILabel in ContainerView.
So I am using this code for that.

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

Now problem is that when i set background color for ContainerView it hides the text of myLabel

Any Solution ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲墙角沉默 2024-12-03 19:46:51

发生的情况是您的containerView被添加到标签上方,您可以在containerView之后添加标签或执行以下操作:

[self.view bringSubviewToFront:myLabel];

What is happening is that you containerView is being added above label either you add label after containerView or do this:

[self.view bringSubviewToFront:myLabel];
简单气质女生网名 2024-12-03 19:46:51

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

[self.view bringSubviewToFront:myLabel];

因为ChallengeView隐藏了标签。

You add the ChallengeView first , Then add the myLabel.
Otherwise u can do as like @xs2bush said,

[self.view bringSubviewToFront:myLabel];

Bcz the ChallengeView hides the label.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文