A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

为啥我这样不行呢 望大神告知啊

  1. #import "ViewController.h"

  2. @interface ViewController ()

  3. @end

  4. @implementation ViewController

  5. - (void)viewDidLoad {
  6.     [super viewDidLoad];
  7.     // Do any additional setup after loading the view, typically from a nib.
  8. #pragma mark - 图片按钮的创建
  9.    
  10.     //1.创建按钮
  11.     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  12.     //2.设置frame
  13.     btn.frame=CGRectMake(50, 50, 50, 50);
  14.     //3.设置按钮图片
  15.     [btn setBackgroundImage:[UIImage imageNamed:@"biaoqingdi"] forState:UIControlStateNormal];
  16.     [btn setBackgroundImage:[UIImage imageNamed:@"danteng"] forState:UIControlStateHighlighted];
  17.     //4.设置图片文字
  18.     [btn setTitle:@"别点我" forState:UIControlStateNormal];
  19.     [btn setTitle:@"真点了" forState:UIControlStateHighlighted];
  20.     //5.设置按钮文字颜色
  21.     [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  22.     [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
  23.     //6.添加到view
  24.     [self.view addSubview:btn];
  25. #pragma mark - 向上
  26.     //1.创建按钮
  27.     UIButton *shang = [UIButton buttonWithType:UIButtonTypeCustom];
  28.     //2.设置frame
  29.     shang.frame = CGRectMake(150, 150, 30, 30);
  30.     //3.设置按钮背景图片
  31.     [shang setBackgroundImage:[UIImage imageNamed:@"top_normal"] forState:UIControlStateNormal];
  32.     [shang setBackgroundImage:[UIImage imageNamed:@"top_highlighted"] forState:UIControlStateHighlighted];
  33.     //4.监听按钮点击事件
  34.     [shang addTarget:self action:@selector(up) forControlEvents:UIControlEventTouchUpInside];
  35.     //5.添加到view
  36.     [self.view addSubview:shang];
  37.    
  38.    
  39. }
  40. -(IBAction)up{
  41. CGRect rect = self.btn.frame;      //为什么这样不行呢
  42. rect.origin.y-=10;
  43. self.btn.frame=rect;
  44.    
  45. }
  46. - (void)didReceiveMemoryWarning {
  47.     [super didReceiveMemoryWarning];
  48.     // Dispose of any resources that can be recreated.
  49. }

  50. @end
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马