从滚动视图中删除标签
我正在创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码中存在一些问题。我假设滚动视图是 self.view 的子视图。在这种情况下,
请从代码中删除该行。根据代码的其余部分,我最终也会更改第一行。如果您不需要在代码中的其他位置超出标签,我会将第一行更改为
并在
[scrollview addSubview: Question];
之后添加一行,这会减少内存消耗。
There are some problems in your code. I assume that the scrollview is a subview of
self.view
. In this case remove the linefrom 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
and add a line after
[scrollview addSubview: question];
withThis would reduce you memory consumption.
为什么要向主视图和滚动视图添加
问题
?这没有道理。删除[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.