码迷,mamicode.com
首页 > 其他好文 > 详细

点击按钮,并且实现增加一个按钮的效果 (附效果图)

时间:2015-06-10 10:26:07      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

不多说,上代码

 

- (void)viewDidLoad {

    [super viewDidLoad];

    [self creatUI];

}

-(void)creatUI

{

    UIButton* add = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    add.frame = CGRectMake(0, 100, 100, 50);

    

    [add setTitle:@"+" forState:UIControlStateNormal];

    [add addTarget:self action:@selector(addannn:) forControlEvents:UIControlEventTouchUpInside];

    [add setBackgroundImage:[UIImage imageNamed:@"jianceku_"] forState:UIControlStateNormal];

    [self.view addSubview:add];

}

//增加按钮的触发事件

-(void)addannn:(UIButton*)sender{

    CGRect frame = sender.frame;

    [UIView animateWithDuration:0.5 animations:^{

        if (sender.frame.origin.x+sender.frame.size.width>=self.view.bounds.size.width) {

            sender.frame = CGRectMake(0, sender.frame.origin.y+sender.frame.size.height, sender.frame.size.width, sender.frame.size.height);

        }else{

            sender.frame = CGRectMake(sender.frame.origin.x+sender.frame.size.width, sender.frame.origin.y, sender.frame.size.width, sender.frame.size.height);

        }

        UIButton* but = [[UIButton alloc]initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width-1, frame.size.height-1)];

        [but setBackgroundImage:[UIImage imageNamed:@"jianceku_"] forState:UIControlStateNormal];

 

        [self.view addSubview:but];

    }];

}

 

 

效果如下:

技术分享

点击按钮,并且实现增加一个按钮的效果 (附效果图)

标签:

原文地址:http://www.cnblogs.com/liaolijun/p/4565194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!