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

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    2020.2.14
    2020.2.13
    规划极限编程阅读笔记03
    学习进度——第十六周
    JSP跳转到Servlet的两种配置
    规划极限编程阅读笔记02
    规划极限编程阅读笔记01
    单词接龙
    学习进度——第十五周
    输入法评价
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/7234177.html
Copyright © 2011-2022 走看看