为啥我这样不行呢 望大神告知啊
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- #pragma mark - 图片按钮的创建
-
- //1.创建按钮
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- //2.设置frame
- btn.frame=CGRectMake(50, 50, 50, 50);
- //3.设置按钮图片
- [btn setBackgroundImage:[UIImage imageNamed:@"biaoqingdi"] forState:UIControlStateNormal];
- [btn setBackgroundImage:[UIImage imageNamed:@"danteng"] forState:UIControlStateHighlighted];
- //4.设置图片文字
- [btn setTitle:@"别点我" forState:UIControlStateNormal];
- [btn setTitle:@"真点了" forState:UIControlStateHighlighted];
- //5.设置按钮文字颜色
- [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
- //6.添加到view
- [self.view addSubview:btn];
- #pragma mark - 向上
- //1.创建按钮
- UIButton *shang = [UIButton buttonWithType:UIButtonTypeCustom];
- //2.设置frame
- shang.frame = CGRectMake(150, 150, 30, 30);
- //3.设置按钮背景图片
- [shang setBackgroundImage:[UIImage imageNamed:@"top_normal"] forState:UIControlStateNormal];
- [shang setBackgroundImage:[UIImage imageNamed:@"top_highlighted"] forState:UIControlStateHighlighted];
- //4.监听按钮点击事件
- [shang addTarget:self action:@selector(up) forControlEvents:UIControlEventTouchUpInside];
- //5.添加到view
- [self.view addSubview:shang];
-
-
- }
- -(IBAction)up{
- CGRect rect = self.btn.frame; //为什么这样不行呢
- rect.origin.y-=10;
- self.btn.frame=rect;
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
复制代码
|
|