UISB XIB登陆例子
作者:互联网
VCRoot.h
#import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface VCRoot : UIViewController //XIB创建UILabel属性 //IBOutlet属性是在XIB中创建的 @property (weak, nonatomic) IBOutlet UILabel *mUserName; //密码属性 @property (weak, nonatomic) IBOutlet UILabel *mUserPassword; //输入对话框属性 @property (weak, nonatomic) IBOutlet UITextField *mTFUserName; @property (weak, nonatomic) IBOutlet UITextField *mTFPassword; //按钮 @property (weak, nonatomic) IBOutlet UIButton *mBTLogin; @property (weak, nonatomic) IBOutlet UIButton *mBTRegister; //按钮函数事件同步 - (IBAction)pressLogin:(UIButton *)sender; - (IBAction)pressRegister:(id)sender; @end
Root.m
- (IBAction)pressRegister:(id)sender { NSString* uName = @"michael"; NSString* uPass=@"123456"; if([_mTFUserName.text isEqual:uName] && [_mTFPassword.text isEqual:uPass]){ NSLog(@"登录成功"); }else { NSLog(@"登陆失败"); } } - (IBAction)pressLogin:(UIButton *)sender { } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [_mTFUserName resignFirstResponder]; [_mTFPassword resignFirstResponder]; }
sceneDelegate.m
#import "SceneDelegate.h" #import "VCRoot.h" @interface SceneDelegate () @end @implementation SceneDelegate - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]; self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); VCRoot* root=[[VCRoot alloc]init]; //对窗口的根视图控制器进行赋值操作 属于windows属性 //整个UIKit框架中只有一个根视图控制器 属于windows的属性 //视图控制器用来管理界面和处理界面逻辑类对象 //程序启动前必须对根视图控制器赋值 self.window.rootViewController=root; //将windos作为主视图并且显示出来 [self.window makeKeyAndVisible]; }
标签:XIB,property,weak,视图,VCRoot,例子,UISB,nonatomic,IBOutlet 来源: https://www.cnblogs.com/zhangqing979797/p/13715436.html