不多说,上代码
效果图
- (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];
}];
}