iOS.UIKit.02.UIButton_UILabel
图01图02 图03图04
一、案例介绍:点击图01中的Button,Label文本变为“Hello World”,如图02。
二、案例步骤:
1、选择Single View Application新建项目,取名cq.39.UIButton_UILabel,如图03。
2、在Main.storyboard中拖一个UIButton和一个UILabel,如图04。
3、代码
#import <UIKit/UIKit.h> @interface CQ39ViewController : UIViewController @property (weak,nonatomic) IBOutlet UILabel *label; - (IBAction)click:(id)sender; @end #import "CQ39ViewController.h" @interface CQ39ViewController () @end @implementation CQ39ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (IBAction)click:(id)sender { self.label.text = @"Hello World!"; } @end
4、连线,如图05,图06,在连接Button时,选择事件Touch Up InSide,command + r运行。
图05图06