【代码笔记】iOS-removeFromSuper

来源:互联网 发布:类似惠头条的软件 编辑:程序博客网 时间:2024/06/08 08:25

代码:

RootViewController.m

复制代码
- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.        self.title=@"removeFromSuperView";            UILabel *tryLabel=[[UILabel alloc]initWithFrame:CGRectMake(50, 150, 200, 50)];    tryLabel.backgroundColor=[UIColor redColor];    [self.view addSubview:tryLabel];    }//当点击任意处时,把UILabel去掉-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    [self removeFromView];}-(void)removeFromView{    //点击后删除之前的PickerView    for (UIView *view in self.view.subviews) {        if ([view isKindOfClass:[UILabel class]]) {            [view removeFromSuperview];        }            }}
复制代码
原创粉丝点击