ios学习之简单的登陆布局
哈哈哈哈哈,成为土豪了,必须买个mac开始装逼了,买了也不能闲着 ,顺便就学学ios吧,就学一个简单的登陆界面,反正什么app都有登陆界面。开动!
先看看效果图:
我可以说很丑吗?
上点代码吧:
// // MineUiViewController.m // UITabview // // Created by xiaoyuan on 15/4/16. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "MineUiViewController.h" @interface MineUiViewController ()<UITextFieldDelegate> { UITextField *phone; UITextField *code; UIButton *btn; UIButton *getcode; } @end @implementation MineUiViewController - (void)viewDidLoad { [super viewDidLoad]; UILabel*title =[[UILabel alloc] initWithFrame:CGRectZero]; title.backgroundColor =[UIColor clearColor]; title.textColor =[UIColor whiteColor]; self.navigationItem.titleView = title; title.text =@"菜鸟"; [title sizeToFit]; self.navigationController.navigationBar.barTintColor = [UIColor redColor]; [self.navigationController.navigationBar setTranslucent:NO]; int width = (self.view.frame.size.width); int leftandright = 6; int top = 6; phone = [[UITextField alloc] initWithFrame:CGRectMake(top, top, width*2/3,50)]; phone.textColor= [UIColor greenColor]; phone.font = [UIFont systemFontOfSize:15]; phone.placeholder =@"请输入手机号"; phone.backgroundColor = [UIColor grayColor]; phone.returnKeyType = UIReturnKeyDefault; phone.keyboardType =UIKeyboardTypeDefault; phone.delegate =self; phone.keyboardType =UIKeyboardTypeNumberPad; [self.view addSubview:phone]; getcode = [[UIButton alloc] initWithFrame:CGRectMake(width*2/3+top*2,top, width*1/3-top*3, 50)]; getcode.backgroundColor =[UIColor blackColor]; [getcode setTitle:@"fuck" forState:UIControlStateNormal]; [getcode addTarget:self action:@selector(getcode) forControlEvents:(UIControlEventTouchUpInside)]; [self.view addSubview:getcode]; int y = 50; y+=20; code = [[UITextField alloc] initWithFrame:CGRectMake(top, y, width-top*2, 50)]; code.textColor= [UIColor blueColor]; code.font = [UIFont systemFontOfSize:15]; code.placeholder =@"请输入验证码"; code.backgroundColor = [UIColor grayColor]; code.returnKeyType = UIReturnKeyDefault; code.keyboardType =UIKeyboardTypeDefault; code.delegate =self; code.keyboardType =UIKeyboardTypeNumberPad; [self.view addSubview:code]; y+=50; y+=20; btn =[[UIButton alloc]initWithFrame:CGRectMake(top, y, width-top*2, 50)]; btn.backgroundColor = [UIColor redColor]; [btn setTitle:@"fuck" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(getcode) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } -(void)getcode { UIAlertView *show = [[UIAlertView alloc] initWithTitle:@"你是逗比吗" message:@"你猜"delegate:nil cancelButtonTitle:@"是" otherButtonTitles:@"是", nil]; [show show]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @en
对了 要想进入这个界面得appdelegate里面改改:
// // AppDelegate.m // UITabview // // Created by xiaoyuan on 15/4/16. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "AppDelegate.h" #import "MineUiViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //创建_window _window=[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 400, 600)]; _window.backgroundColor=[UIColor whiteColor]; MineUiViewController *rootVC=[[MineUiViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootVC]; _window.rootViewController=nav; [_window makeKeyAndVisible]; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end不知道为什么 苹果要加上navigationcontroller 这个不加或者加上这个但是这个是透明的算坐标的时候有点问题啊!新手大神勿喷!
AppDelegate
AppDelegate
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。