从滚动视图中删除标签

发布于 2024-11-30 16:47:56 字数 653 浏览 1 评论 0原文

我正在创建一个 iPhone 应用程序,其中使用滚动视图并添加如下标签:

question = [[UILabel alloc] initWithFrame:CGRectMake(22, 130, 725, 160)] ;
question.textColor = [UIColor blueColor];
question.text = [NSString stringWithFormat:@"%@" ,selected];
question.lineBreakMode = UILineBreakModeWordWrap;
[question setFont:[UIFont fontWithName:@"Futura" size:30]];
question.backgroundColor = [UIColor clearColor];
question.numberOfLines = 0;
[question sizeToFit];
[self.view addSubview:question];
[scrollview addSubview:question];

现在我想从滚动视图中删除此标签。那么我该怎么做呢..??
我这样做是为了从主视图中删除对象。

 [question removeFromSuperview];

谢谢。

I am creating an iPhone app in which i am using scrollview and adding labels like this :

question = [[UILabel alloc] initWithFrame:CGRectMake(22, 130, 725, 160)] ;
question.textColor = [UIColor blueColor];
question.text = [NSString stringWithFormat:@"%@" ,selected];
question.lineBreakMode = UILineBreakModeWordWrap;
[question setFont:[UIFont fontWithName:@"Futura" size:30]];
question.backgroundColor = [UIColor clearColor];
question.numberOfLines = 0;
[question sizeToFit];
[self.view addSubview:question];
[scrollview addSubview:question];

now i want to remove this label from scrollview. So how can i do this..??
i am doing this for remove object from main view.

 [question removeFromSuperview];

Thanks.

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

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

发布评论

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

评论(2

宁愿没拥抱 2024-12-07 16:47:56

您的代码中存在一些问题。我假设滚动视图是 self.view 的子视图。在这种情况下,

[self.view addSubview: question];

请从代码中删除该行。根据代码的其余部分,我最终也会更改第一行。如果您不需要在代码中的其他位置超出标签,我会将第一行更改为

UILabel *question = [[UILabel alloc] initWithFrame: CGRectMake(22, 130, 725, 160)];

并在 [scrollview addSubview: Question]; 之后添加一行,

[question release];

这会减少内存消耗。

There are some problems in your code. I assume that the scrollview is a subview of self.view. In this case remove the line

[self.view addSubview: question];

from you code. Depending on the rest of your code I would eventually also change the first line. If you don't need to excess the label somewhere else in your code I would change the first line to

UILabel *question = [[UILabel alloc] initWithFrame: CGRectMake(22, 130, 725, 160)];

and add a line after [scrollview addSubview: question]; with

[question release];

This would reduce you memory consumption.

不打扰别人 2024-12-07 16:47:56

为什么要向主视图和滚动视图添加问题?这没有道理。删除 [self.view addSubview:question]; 行和 [question removeFromSuperview]; 将从滚动视图中删除标签。

Why are you adding question to the main view and to the scroll view? It doesn't make sense. Remove the [self.view addSubview:question]; line and [question removeFromSuperview]; will remove your label from the scrollview.

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