您的位置:首页 > 移动开发 > IOS开发

button分次点击效果不同(点击button隐藏一个视图,再次点击该视图显示,如此循环)

2014-01-15 10:06 295 查看
//创建一个button,添加在控制器视图

UIButton *addButton = [UIButton buttonWithType:UIButtonTypeContactAdd];

    addButton.backgroundColor = [UIColor clearColor];

    addButton.frame = CGRectMake(0, 440, 40, 40);

    [addButton addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addButton];

//创建一个视图,视图上可以放置其他button,从而达到节省空间的效果.其中.aView为uiview类的属性.

self.aView = [[UIView alloc] initWithFrame:CGRectMake(40, 420, 320, 60)];

    self.aView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:self.aView];

    self.aView.hidden = YES;

//触发的方法

实现机理为循环改变视图的隐藏性.

- (void)add:(UIButton *)button

{

    if (self.aView.hidden == NO) {

        self.aView.hidden = YES;

        

    }else{

        self.aView.hidden = NO;

    }

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS OC button
相关文章推荐