1.AppDelegate.m

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  //初始化windows的大小和位置

    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

    self.window.backgroundColor = [UIColor orangeColor];

    

    KCMainViewController *mainController = [[KCMainViewController alloc]init];

  //设置自定义控制器的大小和window相同,位置为(0,0)

  //设置此控制器为window的根控制器

    mainController.view.frame = self.window.bounds;

    self.window.rootViewController = mainController;

  //设置window为应用程序主窗口,可见

    [self.window makeKeyAndVisible];

    // Override point for customization after application launch.

    return YES;    

}

 

2.

KCMainViewController.h

 

#pragma mark logo

@property (nonatomic,strong) UIImageView *logo;

#pragma mark 手机号码

@property(nonatomic,strong)UITextField *phoneNumber;

#pragma mark 密码

@property(nonatomic,strong)UITextField *password;

#pragma mark 登录按钮

@property (nonatomic,strong)UIButton *loginButton;

 

#pragma mark 点击事件

-(void)login:(UIButton *)btn;

@end

 

3.

KCMainViewController.m

 

//iOS中init一个对象时,会调用对象的init方法,进入init方法时会调用initWithNibName方法,可调试验证

// 以后自定义控制器建议写这个方法,让控制器一创建出来就拥有某些属性

// init方法内部默认会调用initWithNibName方法

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if(self)

    {}

    return self;

}

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    //添加图标

    CGRect logoRect = CGRectMake(100, 501, 100, 200);

    _logo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tubiao.png"]];

  //内容填充

    _logo.contentMode = UIViewContentModeScaleAspectFit;

    _logo.frame = logoRect;

    [self.view addSubview:_logo];

    

    //添加手机号码输入框

    CGRect phoneNumberRect = CGRectMake(20, 320, 280, 30);

    _phoneNumber = [[UITextField alloc]initWithFrame:phoneNumberRect];

  //文本框边框样式

    _phoneNumber.borderStyle = UITextBorderStyleRoundedRect;

    [self.view addSubview:_phoneNumber];

    

    //添加密码输入框

    CGRect passwordRect = CGRectMake(20, 380, 280, 30);

    _password = [[UITextField alloc]initWithFrame:passwordRect];

    _password.borderStyle = UITextBorderStyleRoundedRect;

    [self.view addSubview:_password];

    

   //添加登录按钮

    CGRect loginButtonRect = CGRectMake(10, 440, 300, 25);

    _loginButton = [[UIButton alloc]initWithFrame:loginButtonRect];

    [_loginButton setTitleColor: [UIColor blueColor] forState:UIControlStateNormal];

    [_loginButton setTitle:@"登录" forState:UIControlStateNormal];

    [_loginButton addTarget:self action :@selector(login:)forControlEvents:

     UIControlEventTouchUpInside];

    [self.view addSubview:_loginButton];

}

    

    /*

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

     */

     

   - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    

 

 

    -(void)login:(UIButton *)btn{

        if ([_phoneNumber.text isEqual:@"123"]&&[_password.text isEqual:@"456"]) {

            NSLog(@"登录成功!");

        }else{

            NSLog(@"登录失败!");

        }

    }

 

TextField 详解

posted on 2016-04-07 23:21  Jackson_Yi  阅读(311)  评论(0)    收藏  举报