iOS开发-UI从入门到精通(三)

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

iOS开发-UI 从入门到精通(三)是对 iOS开发-UI 从入门到精通(一)知识点的综合练习,搭建一个简单地登陆界面,增强实战经验,为以后做开发打下坚实的基础!

※在这里我们还要强调一下,开发环境和内存管理注意事项(最后一次强调,以后文章中将不会在出现希望大家谨记):

1、前期iOS-UI开发我们需要手动管理内存,所以我们要把ARC关掉(Xcode关掉ARC的步骤);

(1)打开Xcode选中当前工程:

(2)选中Build Settings:

(3)在输入框内输入count:

(4)选择Objective-C Automatic Reference Counting 将其设置为 NO:

(5)AppDelegate.h文件中将:@PRoperty (assign, nonatomic) UIWindow *window;改成@property (retain, nonatomic) UIWindow *window;

(6)AppDelegate.m文件中重写:- (void)dealloc{[_window release];[super dealloc];}

2、在开发当中我们会用到模拟器下面我们来看一下模拟器添加步骤(Xcode环境下);

(1)打开Xcode选择Window下的Devices:

(2)点击“+”在弹出来的选择框里对 Simulator Name 进行选择:

一、利用所学的知识搭建一个简单地登陆界面界面呈现“账号”、“密码”、“登录”、“忘记密码”、“注册”等:

AppDelegate.h文件中:

1#import<UIKit/UIKit.h>23@interfaceAppDelegate : UIResponder <UIapplicationDelegate>45@property (retain, nonatomic) UIWindow *window;67@end

AppDelegate.m文件中:

1@implementationAppDelegate23- (void)dealloc4{5[_window release];6[super dealloc];7}89- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {10//Override point for customization after application launch.11#pragmamark--:window窗口12self.window =[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];1314_window.backgroundColor =[UIColor whiteColor];1516#pragmamark--:创建一个view17UIView * view =[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];1819view.backgroundColor =[UIColor whiteColor];2021#pragmamark--:创建两个UILabel(账号\密码)22UILabel * numLabel = [[UILabel alloc] initWithFrame:CGRectMake(60,100,50,30)];2324numLabel.text =@"账 号:";2526UILabel * passLabel = [[UILabel alloc] initWithFrame:CGRectMake(60,160,50,30)];2728passLabel.text =@"密 码:";2930#pragmamark--:创建两个UITextField(账号输入框\密码输入框)31UITextField * numTextField = [[UITextField alloc] initWithFrame:CGRectMake(130,100,200,30)];3233numTextField.borderStyle =UITextBorderStyleRoundedRect;3435numTextField.placeholder =@"请输入手机号/邮箱";3637UITextField * passTextField = [[UITextField alloc] initWithFrame:CGRectMake(130,160,200,30)];3839passTextField.borderStyle =UITextBorderStyleRoundedRect;4041passTextField.placeholder =@"请输入密码";4243#pragmamark--:创建三个Button(登录\忘记密码\注册)44UIButton * loginBtn =[UIButton buttonWithType:UIButtonTypeSystem];4546loginBtn.frame = CGRectMake(60,220,40,40);4748[loginBtn setTitle:@"登录"forState:UIControlStateNormal];4950UIButton * forgetBtn =[UIButton buttonWithType:UIButtonTypeSystem];5152forgetBtn.frame = CGRectMake(160,220,60,40);5354[forgetBtn setTitle:@"忘记密码"forState:UIControlStateNormal];5556UIButton * regisBtn =[UIButton buttonWithType:UIButtonTypeSystem];5758regisBtn.frame = CGRectMake(280,220,40,40);5960[regisBtn setTitle:@"注册"forState:UIControlStateNormal];6162#pragmamark--:添加到视图上63[view addSubview:regisBtn];6465[view addSubview:forgetBtn];6667[view addSubview:loginBtn];6869[view addSubview:passTextField];7071[view addSubview:numTextField];7273[view addSubview:passLabel];7475[view addSubview:numLabel];7677[_window addSubview:view];7879[_window makeKeyAndVisible];8081#pragmamark--:释放82[passTextField release];8384[numTextField release];8586[passLabel release];8788[numLabel release];8990[view release];9192[_window release];9394returnYES;95}9697@end

模拟器运行效果图:

下一篇将持续更新配套知识点及练习;

Email:dingding3w@126.com

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航