#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *iconView;
- (IBAction)right;
- (IBAction)top;
- (IBAction)plus;
- (IBAction)bottom;
//移动
- (IBAction)move:(UIButton *)sender;
@end
@implementation ViewController
//当界面打开之后就会调用这个方法 js--window.onload
- (void)viewDidLoad {
[super viewDidLoad];
//添加一个按钮
UIButton *btn=[[UIButton alloc] init];
//将按钮添加到view
[self.view addSubview:btn];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//使用center属性进行坐标的修改,使用center不能修改控件的大小
- (IBAction)right {
CGPoint temp=self.iconView.center;
temp.x+=10;
temp.y+=10;
self.iconView.center=temp;
}
//向上移动iconView
- (IBAction)top {
//注意:不能直接修改 一个对象 的结构体属性 的成员值, 但是你可以修改一个结构体成员的属性值
//self.iconView.frame.origin.y-=10;
//1.获取iconVIew的Frame,存储到临时变量中
CGRect temp=self.iconView.frame;
//2.修改临时变量的成员值
temp.origin.y-=10;
temp.origin.x+=10;
temp.size.width+=10;
temp.size.height+=10;
//3.重新赋值
self.iconView.frame=temp;
}
//放大图片
- (IBAction)plus {
// self.iconView.frame.size.width+=10;
// self.iconView.frame.size.height+=10;
//1.获取iconView的frame,存储到临时变量中
CGRect temp=self.iconView.frame;
//2.修改临时变量的宽高值
temp.size.width+=10;
temp.size.height+=10;
//3.重新赋值
self.iconView.frame=temp;
}
//向下 bounds:边界,它能来描述当前控件的大小
- (IBAction)bottom {
CGRect temp= self.iconView.bounds;
// temp.size.width+=10;
// temp.size.height+=10;
temp.origin.x+=20;
temp.origin.y+=20;
self.iconView.bounds=temp;
}
//多控件 共用一个方法连线--Tag值的使用
//sender:事件源就是你操作 那一个控件 来触发当前这个方法操作
- (IBAction)move:(UIButton *)sender {
//判断你所点击的控件 ,进行相应的操作
CGRect temp=self.iconView.frame;
switch (sender.tag) {
case 1:
temp.origin.y-=10;
break;
case 2:
temp.origin.x+=10;
break;
case 3:
temp.origin.y+=10;
break;
}
self.iconView.frame=temp;
}
@end