IOS-學習記錄【01】

來源:互聯網
上載者:User

標籤:ges   ram   引用   icon   self   相關   tar   tom   dispose   

很久都沒寫部落格了,從今天開始會記錄一些學習的心得/過程。現在對學習iOS的興趣也越來越濃。小程式的開發已經告一段落,目前會對產品進行代碼改進和功能最佳化。

第一個iOS應該從今天開始誕生,這兩天剛開始接觸一些iOS的文法,OC對象的概念還沒有完全熟悉,感覺很全新。

////  ViewController.m//  more////  Created by vjia on 2017/8/1.//  Copyright ? 2017年 vjia. All rights reserved.//#import "ViewController.h"#import "UIKit/UIkit.h"@interface ViewController (){    UITextField *_txtUserName;//聲明控制項變數    UITextField *_txtPassword;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [self LoadLoginForm];//在當前對象中載入}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}-(void)LoadLoginForm{//執行個體化載入控制項    UILabel *lbUserName=[[UILabel alloc] initWithFrame:CGRectMake(20, 160, 100, 40)];//繪製文字框大小    [email protected]"使用者名稱:";//設定文字框文字    [self.view addSubview:lbUserName];        _txtUserName=[[UITextField alloc] initWithFrame:CGRectMake(80, 160, 280, 40)];//繪製文字框大小    [_txtUserName setBorderStyle:UITextBorderStyleRoundedRect];//設定邊框樣式    _txtUserName.layer.borderColor=[[UIColor grayColor] CGColor];//設定邊框的顏色    _txtUserName.layer.borderWidth=0.7f;//設定邊框寬度    _txtUserName.layer.cornerRadius=6.0f;//設定圓角邊框大小    [email protected]"請輸入使用者名稱";    _txtUserName.clearButtonMode=UITextFieldViewModeAlways;//文字框右側總是顯示刪除角標    [self.view addSubview:_txtUserName];//將控制項加入當前的view中        UILabel *lbPassWord=[[UILabel alloc] initWithFrame:CGRectMake(20, 220, 100,40)];    [email protected]"密碼:";    [self.view addSubview:lbPassWord];        _txtPassword=[[UITextField alloc] initWithFrame:CGRectMake(80, 220, 280, 40)];    [_txtPassword setBorderStyle:UITextBorderStyleRoundedRect];    _txtPassword.layer.borderColor=[[UIColor grayColor] CGColor];    _txtPassword.layer.borderWidth=0.7f;    _txtPassword.layer.cornerRadius=6.0f;    [email protected]"請輸入密碼";    _txtPassword.clearButtonMode=UITextFieldViewModeAlways;    [self.view addSubview:_txtPassword];        UILabel *lbForget=[[UILabel alloc] initWithFrame:CGRectMake(20, 280, 100, 50)];    [email protected]"忘記密碼?";    [lbForget setTextColor:[UIColor blueColor]];    [self.view addSubview:lbForget];        UILabel *lbReg=[[UILabel alloc]initWithFrame:CGRectMake(320, 280, 100, 50)];    [email protected]"注 冊";    [lbReg setTextColor:[UIColor redColor]];//設定字型的顏色    [self.view addSubview:lbReg];        CGRect rect=[[UIScreen mainScreen] bounds];//擷取主畫面對象    CGSize size=rect.size;//螢幕大小    CGFloat width=size.width;//寬度        UIButton *btnLogin=[UIButton buttonWithType:UIButtonTypeCustom];//如果按鈕需要自訂背景圖片 按鈕必須設定成自訂模式 否則會看見藍色的表徵圖    btnLogin.frame=CGRectMake(0,400, width, 80+10);    //[btnLogin setBackgroundColor:[UIColor redColor]];//設定背景顏色為紅色    [btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];    [btnLogin setTitle:@"登 錄" forState:UIControlStateNormal];    [btnLogin.self addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];    [btnLogin setImage:[UIImage imageNamed:@"SourceBundle.bundle/login"] forState:UIControlStateNormal];//引用資源檔中的圖片作為背景圖    [btnLogin setImageEdgeInsets:UIEdgeInsetsMake(0, 25, 20, 25)];    [self.view addSubview:btnLogin];        UINavigationBar *navigationbar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, width, 50+10)];//繪製導航    [self.view addSubview:navigationbar];//加入到當前的view中        UINavigationItem *navitem=[[UINavigationItem alloc] initWithTitle:@"登入"];//建立導航內容並設定標題        UIBarButtonItem *barbutton=[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(login)];//在導覽列上建立一個按鈕 文字為返回 加入觸發事件的方法        navitem.leftBarButtonItem=barbutton;//按鈕顯示在導覽列的左側        [navigationbar pushNavigationItem:navitem animated:NO];//將導覽列顯示出來}-(void)login{//登入方法    NSString *message=[NSString stringWithFormat:@"戶名 %@ 密碼 %@",_txtUserName.text,_txtPassword.text];//聲明一個string類型的變數 並接收文字框的輸入的內容    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"溫馨提示" message:message delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];//初始化彈窗    [alert show];//彈出模態表單提示        }@end

 

相關的說明已經在注釋裡面寫了。感覺這種方式剛開始學可能編寫代碼會相對繁瑣,後面應該會很好理解的。還有一種方式是拖控制項來實現,這種會相對簡單些。

小白一個,僅記錄學習的心得與分析學習的過程。

IOS-學習記錄【01】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.