在iOS中显示和删除相同的按钮

时间:2014-07-29 10:38:24

标签: ios objective-c uiview uibutton

我有一个UIButton。现在我在Subview添加按钮: -

UIButton* button4 = [[UIButton alloc] initWithFrame:frame4];
[button4 setBackgroundImage:image3 forState:UIControlStateNormal];
[button4 setShowsTouchWhenHighlighted:YES];
[button4 addTarget:self action:@selector(Nofication:) forControlEvents:UIControlEventTouchDown];

- (void)Nofication:(id)sender
{
    share=[[UIView alloc]init];
    share.frame=CGRectMake(300, 60, 130, 100);
    [self.view addSubview:share];

    [UIView animateWithDuration:2.0
                     animations:^{
                         share.frame =CGRectMake(180, 50, 130, 100); // its final location
                     }];
    share.backgroundColor=[UIColor yellowColor];

    login=[[UIButton alloc]init];
    login.frame=CGRectMake(0, 0, 130, 50);
    [login setBackgroundImage:[UIImage imageNamed:@"login.png"] forState:UIControlStateNormal];
    [login addTarget:self action:@selector(asubmit:) forControlEvents:UIControlEventTouchDown];
    [share addSubview:login];
    login.layer.borderColor = [[UIColor whiteColor]CGColor];

    policies=[[UIButton alloc]init];
    policies.frame=CGRectMake(0, 50, 130, 50);
    [policies setBackgroundImage:[UIImage imageNamed:@"Policies.png"] forState:UIControlStateNormal];
    [policies addTarget:self action:@selector(apolicies:) forControlEvents:UIControlEventTouchDown];

    [share addSubview:policies];
  }

当我点击按钮时,它的开放子视图工作得很好。但是现在我需要如果子视图在那个时间单击按钮显示它需要隐藏子视图。如果我点击按钮时未显示subview,则需要显示subview。所以请给我任何想法。

如何显示和隐藏相同的UIButton

先谢谢。

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

是什么问的? 子视图是视图(或UIButton),如果显示,则试图隐藏,并显示是否隐藏。

[subview setHidden:![subview isHidden]];

编辑: 在Notification函数中:

// Be sure that the view is loaded, maybe load it at a different place or use a boolean

if([subview isHidden]){
    [subview setHidden:false];
}else{
    [subview setHidden:true];
}

答案 2 :(得分:0)

您可以在button4.selected = !button4.selected方法中设置Nofication:。 然后,您可以检查button4.isSelected并使用hidden属性隐藏/显示子视图

希望它有所帮助。

相关问题