zoukankan      html  css  js  c++  java
  • iOS开发之按钮的基本使用

    实现功能:

    点击向上的箭头,按钮图片向上,移动,点击向下的箭头,按钮图片向下移动

    点击向左的箭头,按钮图片向左移动,点击向右的箭头,按钮图片向右移动,

    点击加号图片放大,点击减号,图片缩小

     

     

     

     

    第一步: 搭建界面,将控件分别连线

    第二步: 将图片按钮连线

    @property (weak, nonatomic) IBOutlet UIButton *headBtn;

     

     

    第三步: 在每个按钮点击事件中实现向上,向下,向左,向右,放大,缩小的功能

     

    //想上

    - (IBAction)up:(id)sender {

    //    NSLog(@"");

    //    self.headBtn.frame.origin.y = self.headBtn.frame.origin.y - 10;

        //不能直接访问对象的结构体属性的成员变量

        //能够直接访问对象的结构体属性

    //    self.headBtn.frame

        //1 取出对象的结构体属性frame 赋值给临时的变量

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

    //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.origin.y -= 10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

        

    }

    //向下

    - (IBAction)down:(id)sender {

    //    NSLog(@"");

        //1 取出对象的结构体属性frame 赋值给临时的变量

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

        //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.origin.y += 10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

    }

     

    /**

     向左

     

     

     */

    - (IBAction)left:(id)sender {

    //    NSLog(@"");

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

        //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.origin.x -= 10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

    }

     

    /**

     向右

     

     @param sender <#sender description#>

     */

    - (IBAction)right:(id)sender {

    //    NSLog(@"");

        //1 取出对象的结构体属性frame 赋值给临时的变量

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

        //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.origin.x += 10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

    }

     

     

     

    /**

     放大

     

     @param sender <#sender description#>

     */

    - (IBAction)big:(id)sender {

        

    //    NSLog(@"");

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

        //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.size.width += 10;

        tempFrame.size.height +=10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

     

    }

     

    /**

     缩小

     

     @param sender <#sender description#>

     */

    - (IBAction)small:(id)sender {

    //   NSLog(@"");

        CGRect tempFrame = self.headBtn.frame;

        //2 修改临时变量的值

        //    tempFrame.origin.y = tempFrame.origin.y - 10;

        //

        tempFrame.size.width -= 10;

        tempFrame.size.height -=10;

        //3 用临时变量的值覆盖原来的值

        self.headBtn.frame = tempFrame;

        

    }

    @end

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    1.1/1.1.1-玩转Python3金融API应用-easyutils的Readme文件
    1-玩转Python3金融API应用-查阅easytrader家族系列模块
    0-玩转Python3金融API应用-学习查阅API资料的重要性及怎样学
    一句sql搞定身份证校验位
    python爬虫--爬取某网站电影信息并写入mysql数据库
    Mysql简单笔记
    python爬虫--爬取某网站电影下载地址
    android dalvik heap管理分析
    dlmalloc 简析
    low memory killer配置的思考
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/7234177.html
Copyright © 2011-2022 走看看