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

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

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

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

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

(2)选中Build Settings:

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

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

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

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

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

(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:

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

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

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

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

AppDelegate.h文件中:

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (retain, nonatomic) UIWindow *window;

 @end

AppDelegate.m文件中:

 @implementation AppDelegate

 - (void)dealloc
{
[_window release];
[super dealloc];
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#pragma mark--:window窗口
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window.backgroundColor = [UIColor whiteColor]; #pragma mark--:创建一个view
UIView * view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; view.backgroundColor = [UIColor whiteColor]; #pragma mark--:创建两个UILabel(账号\密码)
UILabel * numLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )]; numLabel.text = @"账 号:"; UILabel * passLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )]; passLabel.text = @"密 码:"; #pragma mark--:创建两个UITextField(账号输入框\密码输入框)
UITextField * numTextField = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; numTextField.borderStyle = UITextBorderStyleRoundedRect; numTextField.placeholder = @"请输入手机号/邮箱"; UITextField * passTextField = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; passTextField.borderStyle = UITextBorderStyleRoundedRect; passTextField.placeholder = @"请输入密码"; #pragma mark--:创建三个Button(登录\忘记密码\注册)
UIButton * loginBtn = [UIButton buttonWithType:UIButtonTypeSystem]; loginBtn.frame = CGRectMake(, , , ); [loginBtn setTitle:@"登录" forState:UIControlStateNormal]; UIButton * forgetBtn = [UIButton buttonWithType:UIButtonTypeSystem]; forgetBtn.frame = CGRectMake(, , , ); [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal]; UIButton * regisBtn = [UIButton buttonWithType:UIButtonTypeSystem]; regisBtn.frame = CGRectMake(, , , ); [regisBtn setTitle:@"注册" forState:UIControlStateNormal]; #pragma mark--:添加到视图上
[view addSubview:regisBtn]; [view addSubview:forgetBtn]; [view addSubview:loginBtn]; [view addSubview:passTextField]; [view addSubview:numTextField]; [view addSubview:passLabel]; [view addSubview:numLabel]; [_window addSubview:view]; [_window makeKeyAndVisible]; #pragma mark--:释放
[passTextField release]; [numTextField release]; [passLabel release]; [numLabel release]; [view release]; [_window release]; return YES;
} @end

模拟器运行效果图:

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

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

Email:[email protected]

04-02 16:10