iOS开发-UI基础Demo

十度 IOS 2015年12月01日 收藏

现在更多的学习资料都是xCode4.X的,发现xCode6.1还是很多东西,如果有正在学习iOS开发的可以通过Demo简单了解下iOS的UI开发~

1.新建单视图文件:

2.新建项目名称,语言选择OC:

3.这个就是拖了两个控件放在View上面的,其中有一个比Android好的就是不需要自己新建模拟器,取消一下自动布局和auto size classes,不然页面很大:

4.如果你只是简单的写个Hello  World,那么这个程序已经结束了,不过第一次还是做个事件:

5.新手错误之this class is not key value coding-compliant for the key result,这个就是连线连太多了,连错了,结果连接那边没有删除,具体修改如下:

6.运行效果如下:

7.代码如下:

  1. ViewController.h中代码:
  1. //
  2. // ViewController.h
  3. // Demo01
  4. //
  5. // Created by keso on 15/1/12.
  6. // Copyright (c) 2015年 keso. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10.  
  11. @interface ViewController : UIViewController
  12.  
  13. @property (weak, nonatomic) IBOutlet UIView *name;
  14. @property (weak, nonatomic) IBOutlet UITextField *realName;
  15. @property (weak, nonatomic) IBOutlet UILabel *result;
  16.  
  17. @end

 ViewController.m中代码:

  1. //
  2. // ViewController.m
  3. // Demo01
  4. //
  5. // Created by keso on 15/1/12.
  6. // Copyright (c) 2015年 keso. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @end
  14.  
  15. @implementation ViewController
  16.  
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view, typically from a nib.
  20. }
  21.  
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. - (IBAction)showName:(id)sender {
  27. NSString *textName=[_realName text];
  28. [_result setText:textName];
  29. }
  30.  
  31. @end