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

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/LiLihongqiang/p/7234177.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值