點擊button, labe區顯示文字

1.點選storyboard, 拖曳一個label與一個button到view controller上

2.按住alt點選viewController.h檔, 滑鼠右鍵點選label往右拉到viewController.h, 設定為outlet, 並且命名為labelArea

3.滑鼠右鍵點選button往右拉到viewController.h, 設定為action, 並且命名為toClick

4.點選viewController, 將_labelArea.text=@"hello world";寫進toClick之method中

5.按住command+R執行


//viewController.h內容如下

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
 
- (IBAction)toClick:(id)sender;

@property (weak, nonatomic) IBOutletUILabel *showArea;

@end

//viewController.m內容如下

#import "ViewController.h"

@interfaceViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}
- (IBAction)toClick:(id)sender {

    _labelArea.text=@"hello world";
}

@end

 IMG_4663.PNG  

arrow
arrow

    Will 發表在 痞客邦 留言(0) 人氣()