zoukankan      html  css  js  c++  java
  • 点击按钮,并且实现增加一个按钮的效果 (附效果图)

    不多说,上代码

    效果图

     

    - (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];

        }];

    }

  • 相关阅读:
    Redis数据库
    python的web运用
    python对 if __name__=='__main__'的理解
    python的函数
    python的四种内置数据结构
    python的循环和选择
    关于oracle设置主键自增的问题
    用HttpClient和用HttpURLConnection做爬虫发现爬取的代码少了的问题
    ORACLE not available如何解决
    集合(下)
  • 原文地址:https://www.cnblogs.com/liaolijun/p/4565194.html
Copyright © 2011-2022 走看看