iOS開發-UI 從入門到精通(三)


 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>
2 
3 @interface AppDelegate : UIResponder <UIApplicationDelegate>
4 
5 @property (retain, nonatomic) UIWindow *window;
6 
7 @end

AppDelegate.m文件中:

 

 1 @implementation AppDelegate
 2 
 3 - (void)dealloc
 4 {
 5     [_window release];
 6     [super dealloc];
 7 }
 8 
 9 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
10     // Override point for customization after application launch.
11 #pragma mark--:window窗口
12     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
13     
14     _window.backgroundColor = [UIColor whiteColor];
15     
16 #pragma mark--:創建一個view
17     UIView * view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
18     
19     view.backgroundColor = [UIColor whiteColor];
20     
21 #pragma mark--:創建兩個UILabel(賬號\密碼)
22     UILabel * numLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 50, 30)];
23     
24     numLabel.text = @"賬  號:";
25     
26     UILabel * passLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 160, 50, 30)];
27     
28     passLabel.text = @"密  碼:";
29     
30 #pragma mark--:創建兩個UITextField(賬號輸入框\密碼輸入框)
31     UITextField * numTextField = [[UITextField alloc] initWithFrame:CGRectMake(130, 100, 200, 30)];
32     
33     numTextField.borderStyle = UITextBorderStyleRoundedRect;
34     
35     numTextField.placeholder = @"請輸入手機號/郵箱";
36     
37     UITextField * passTextField = [[UITextField alloc] initWithFrame:CGRectMake(130, 160, 200, 30)];
38     
39     passTextField.borderStyle = UITextBorderStyleRoundedRect;
40     
41     passTextField.placeholder = @"請輸入密碼";
42     
43 #pragma mark--:創建三個Button(登錄\忘記密碼\注冊)
44     UIButton * loginBtn = [UIButton buttonWithType:UIButtonTypeSystem];
45     
46     loginBtn.frame = CGRectMake(60, 220, 40, 40);
47     
48     [loginBtn setTitle:@"登錄" forState:UIControlStateNormal];
49     
50     UIButton * forgetBtn = [UIButton buttonWithType:UIButtonTypeSystem];
51     
52     forgetBtn.frame = CGRectMake(160, 220, 60, 40);
53     
54     [forgetBtn setTitle:@"忘記密碼" forState:UIControlStateNormal];
55     
56     UIButton * regisBtn = [UIButton buttonWithType:UIButtonTypeSystem];
57     
58     regisBtn.frame = CGRectMake(280, 220, 40, 40);
59     
60     [regisBtn setTitle:@"注冊" forState:UIControlStateNormal];
61     
62 #pragma mark--:添加到視圖上
63     [view addSubview:regisBtn];
64     
65     [view addSubview:forgetBtn];
66     
67     [view addSubview:loginBtn];
68     
69     [view addSubview:passTextField];
70     
71     [view addSubview:numTextField];
72     
73     [view addSubview:passLabel];
74     
75     [view addSubview:numLabel];
76     
77     [_window addSubview:view];
78     
79     [_window makeKeyAndVisible];
80     
81 #pragma mark--:釋放
82     [passTextField release];
83     
84     [numTextField release];
85     
86     [passLabel release];
87     
88     [numLabel release];
89     
90     [view release];
91     
92     [_window release];
93 
94     return YES;
95 }
96 
97 @end

 

 

 

 

模擬器運行效果圖:

          

下一篇將持續更新配套知識點及練習;

 Email:dingding3w@126.com

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM