仿制QQ界面

来源:互联网 发布:易观的数据来源 编辑:程序博客网 时间:2024/06/05 17:03


[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. #pragma mark - @主绘制画面  
  2. - (void)viewDidLoad  
  3. {  
  4.     [super viewDidLoad];  
  5.     // Do any additional setup after loading the view.  
  6.       
  7.     #pragma mark 1.设置View的背景图片  
  8.     UIColor *bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"002.jpg"]];  
  9.     [self.view setBackgroundColor:bgColor];  
  10.       
  11.     #pragma mark 2.绘制账号  
  12.     self.userLabel = [[UILabel alloc]initWithFrame:CGRectMake(201205040)];  
  13.     self.userLabel.text = @"账号";  
  14.     [self.userLabel setFont:[UIFont boldSystemFontOfSize:20.0]];  
  15.     [self.view addSubview:self.userLabel];  
  16.     [self.userLabel release];  
  17.       
  18.     self.userText = [[UITextField alloc]initWithFrame:CGRectMake(self.userLabel.right , self.userLabel.top,self.userLabel.width+170 , self.userLabel.height)];  
  19.     self.userText.borderStyle = UITextBorderStyleRoundedRect;  
  20.     self.userText.placeholder = @"手机号/会员名/邮箱";  
  21.     self.userText.clearButtonMode = UITextFieldViewModeAlways;   // 使输入框后面有个小"x"  用来执行一次性删除  
  22.     self.userText.keyboardType = UIKeyboardAppearanceDefault;  
  23.     self.userText.keyboardAppearance = UIKeyboardAppearanceAlert;  
  24.     self.userText.returnKeyType = UIReturnKeyJoin;  
  25.     self.userText.delegate = self;  
  26.     [self.view addSubview:self.userText];  
  27.     [self.userText release];  
  28.       
  29.     #pragma mark 3.绘制密码  
  30.     _pwdLabel = [[UILabel alloc]initWithFrame:CGRectMake(201705040)];  
  31.     _pwdLabel.text = @"密码";  
  32.     [_pwdLabel setFont:[UIFont boldSystemFontOfSize:20.0]];  
  33.     [self.view addSubview:_pwdLabel];  
  34.     [_pwdLabel release];  
  35.       
  36.     _pwdText = [[UITextField alloc]initWithFrame:CGRectMake(_pwdLabel.right, _pwdLabel.top, _pwdLabel.width+170, _pwdLabel.height)];  
  37.     _pwdText.borderStyle = UITextBorderStyleRoundedRect;  
  38.     _pwdText.placeholder = @"password";  
  39.     _pwdText.secureTextEntry = YES;  
  40.     _pwdText.clearButtonMode = UITextFieldViewModeAlways;  
  41.     _pwdText.keyboardType = UIKeyboardTypeEmailAddress;  
  42.     _pwdText.keyboardAppearance = UIKeyboardAppearanceAlert;  
  43.     _pwdText.returnKeyType = UIReturnKeyJoin;  
  44.     _pwdText.delegate = self;  
  45.     [self.view addSubview:_pwdText];  
  46.     [_pwdText release];  
  47.       
  48.     #pragma mark 4.绘制是否记住密码控件  
  49.     _isLabel = [[UILabel alloc]initWithFrame:CGRectMake(2021010040)];  
  50.     _isLabel.text = @"记住密码";  
  51.     [_isLabel setFont:[UIFont boldSystemFontOfSize:20.0]];  
  52.     [self.view addSubview:_isLabel];  
  53.     [_isLabel release];  
  54.       
  55.     _isISwitch = [[UISwitch alloc]initWithFrame:CGRectMake(23021540, _isLabel.height)];  
  56.     [_isISwitch addTarget:self action:@selector(openOrClosed:) forControlEvents:UIControlEventValueChanged];  
  57.     [self.view addSubview:_isISwitch];  
  58.       
  59.     #pragma mark 5.绘制登录按钮  
  60.     _login = [UIButton buttonWithType:UIButtonTypeSystem];  
  61.     _login.frame = CGRectMake(4025024040);  
  62.     [_login.titleLabel setFont:[UIFont boldSystemFontOfSize:30.0]];    // 设置字体大小  
  63.     _login.tintColor = [UIColor blackColor];  
  64.     [_login setBackgroundImage:[UIImage imageNamed:@"login1.png"] forState:UIControlStateNormal];  // 设置按钮的背景图片  
  65.     [_login setTitle:@"登录" forState:UIControlStateNormal];  
  66.     [_login addTarget:self action:@selector(loginView:) forControlEvents:UIControlEventTouchUpInside];  
  67.       
  68.     [self.view addSubview:_login];  
  69.       
  70. }  
  71.   
  72. #pragma mark - @响应是否记住密码开关  
  73. - (IBAction)openOrClosed:(id)sender{  
  74.   
  75.     UISwitch * switchButton = (UISwitch *)sender;  
  76.     if ([switchButton isOn]) {  
  77.         NSLog(@"YES");  
  78.     } else {  
  79.         NSLog(@"NO");  
  80.     }  
  81.       
  82. }  
  83.   
  84.   
  85. #pragma mark - @响应点击登录按钮  
  86. - (IBAction)loginView:(id)sender{  
  87.   
  88.     HMTMainViewController * mainVC = [[HMTMainViewController alloc]init];  
  89.     UINavigationController * mainNC = [[UINavigationController alloc]initWithRootViewController:mainVC];  
  90.     // 模态视图控制器呈现出来时候的视觉效果  
  91.     mainVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;  
  92.     // 模态视图控制器呈现方式,默认全屏  
  93.     mainVC.modalPresentationStyle = UIModalPresentationFullScreen;  
  94.   
  95.     NSString * userString = self.userText.text;  
  96.     NSString * pwdString  = self.pwdText.text;  
  97.     if ([userString isEqualToString:@"23423423424"] && [pwdString isEqualToString:@"hE2342340"] ) {  
  98.           
  99.         [self presentViewController:mainNC animated:YES completion:^{  
  100.             NSLog(@"登陆成功");  
  101.         }];  
  102.           
  103.     } else {  
  104.         NSLog(@"用户名或者密码错误");  
  105.     }  
  106.       
  107.   
  108.     [mainNC release];  
  109.     [mainVC release];  
  110.   
  111.     #pragma mark 第3种方式收回键盘  
  112.     // 当前视图结束编辑  
  113.     [self.view endEditing:YES];  
  114. }  
  115.   
  116. #pragma mark - @3种方法来收回弹出来的键盘  
  117. #pragma mark  第1种方式来收回键盘 -------> 通过UITextField本身的协议来实现  
  118. - (BOOL)textFieldShouldReturn:(UITextField *)textField  
  119. {  
  120.     // 放弃第一响应者  
  121.     [textField resignFirstResponder];  
  122.     return YES;  
  123. }  
  124.   
  125. #pragma mark  第2种方式来收回键盘 -------> 通过重写UIResponder的方法  
  126. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{  
  127.       
  128.     // selfself.view.subviews 返回的是加载在View视图上的所有视图的数组  
  129.     [self.view.subviews enumerateObjectsUsingBlock:^(UIView* obj, NSUInteger idx, BOOLBOOL *stop) {  
  130.         if ([obj isKindOfClass:[UITextField class]]) {  
  131.             [obj resignFirstResponder];  
  132.         }  
  133.     }];  
  134.   
  135. }  
0 0
原创粉丝点击