Objc

iOS 中添加按钮和按钮监听方法

Sep 1, 2014
Objc

代码添加按钮和按钮监听方法 // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)tapButton:(UIButton *)sender{ NSLog(@"我是%@",[sender.titleLabel text]); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake(100, 100, 200, 200)]; [button setTitle:@"hello" forState:UIControlStateNormal]; [button ...

iOS 中 textFieldShouldReturn 方法的使用

Aug 31, 2014
Objc

iOS 中 textFieldShouldReturn 方法定义在 UITextFieldDelegate 协议中 // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (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. } - (BOOL)textFieldShouldReturn:(UITextField *)textField{ if (textField==_name) { [_passwd becomeFirstResponder]; }else if(textField==_passwd){ [self login:nil]; } return YES; } - (IBAction)login:(id)sender { [self.view endEditing:NO]; NSString *name = _name.text; NSString *passwd = _passwd.text; [_lable setText:[NSString stringWithFormat:@"username:%@ password:%@",name,passwd]]; } @end