Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何删除drawInRect后的文本?_Iphone_Nsstring - Fatal编程技术网

Iphone 如何删除drawInRect后的文本?

Iphone 如何删除drawInRect后的文本?,iphone,nsstring,Iphone,Nsstring,我有一个名为BackgroundText的UIView子类来绘制一些文本 -(void) drawRect:(CGRect)rect { [@"synchronized." drawInRect:CGRectMake(0, 29, 320, 60) withFont:bigFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentRight]; } -- 我希望[backgroundText re

我有一个名为BackgroundText的UIView子类来绘制一些文本

-(void) drawRect:(CGRect)rect
{
    [@"synchronized." drawInRect:CGRectMake(0, 29, 320, 60) withFont:bigFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentRight];
}
--

我希望
[backgroundText removeFromSuperview]
可以从屏幕上删除这些文本,但它不起作用


谢谢。

您需要在视图中调用
setNeedsDisplay
并进行检查。

我希望这对您有所帮助

这里,加载BG是我的视图,加载文本是我的标签,我将文本放入标签,并将标签添加到视图中,然后在不需要文本时从SuperView中删除视图

用于添加文本:

UIView * LoadingBG = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460);
UILabel *LoadingText = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)] autorelease];
LoadingText.text = @"Loading...";
LoadingText.backgroundColor = [UIColor clearColor];
[LoadingBG addSubview:LoadingText];
[LoadingBG removeFromSuperview];
用于删除文本:

UIView * LoadingBG = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460);
UILabel *LoadingText = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)] autorelease];
LoadingText.text = @"Loading...";
LoadingText.backgroundColor = [UIColor clearColor];
[LoadingBG addSubview:LoadingText];
[LoadingBG removeFromSuperview];

在这里,我使用了固定大小的视图和标签。你可以使用你想要的作为一个框架。

你的意思是在我调用
[backgroundText removeFromSuperview]之后?尝试过但失败了。这可能是因为我每次需要时都会初始化一个新的背景文本。将init代码放到viewDidLoad之后,它就可以工作了。谢谢巴普和阿卜杜拉