一、创建项目,选择Application-Single View Application
二、填写对应的输入项,项目名称等
三、在项目的视图文件中,拖入对应的控件,如下图:
四、 .h 文件声明对应的 属性,可以使用xcode从视图,选中控件、同时按住control键拖入.h文件中,然后输入控件id
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
}
@property (weak, nonatomic) IBOutlet UITextField *txtUserName;
@property (weak, nonatomic) IBOutlet UITextField *txtUserPwd;
- (IBAction)onclick_UserLogin:(id)sender;
@end
五、.m 文件,关联属性,实现声明的 onclick_UserLogin 方法
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize txtUserName;
@synthesize txtUserPwd;
- (IBAction)onclick_UserLogin:(id)sender{
txtUserName.text = @"高江涛、卓轩";
txtUserPwd.text = @"Hello";
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
六、btn点击事件关联
七、最终运行效果: