开发者

Remove label from scrollview

开发者 https://www.devze.com 2023-03-29 05:41 出处:网络
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)] ;

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 = [UIColo开发者_开发知识库r 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号