#在藍懿學習iOS的日子#Day2

來源:互聯網
上載者:User

標籤:

#在藍懿學習iOS的日子#今天的學習的東西好多,當是每天的筆記吧:

1. 變數的範圍 

局部變數:只可以在大括弧內{}的範圍為內使用;

全域變數:

在@interface ViewController ()的大括弧內{}設定的變數u都j是全域變數,但不可以賦值

例:@interface ViewController (){

    UIImageView *bulletIV;

    float x;

    int m;

}

2.布爾值:BOOL  取值0或1   即:1是表示條件成立,0表示條件不成立;

3.if語句  else  else if:是用來判斷條件的是否成立的:

例:

if (i%3==0) {

     mylbel.backgroundColor = [UIColor redColor];

     }else if (i%3==1){

         mylbel.backgroundColor = [UIColor yellowColor];

    }else{//其它

   mylbel.backgroundColor = [UIColor blueColor];

    }

4.switch-Case語句是只可以用z數值代替用來判斷的條件,break是指結束當前的cases

例: switch (i%4) {

      case 0:

      mylbel.backgroundColor = [UIColor redColor];

      break;

        case 1:

       mylbel.backgroundColor = [UIColor yellowColor];

       break;

         case 2:

         mylbel.backgroundColor = [UIColor blueColor];

         break;

         default:

         mylbel.backgroundColor = [UIColor grayColor];

          break;

    }

5.按鈕加tag:就是為同一使用的幾個按鈕button設定一個tag值,方便調用;

6.for迴圈  用於n需要重複執行的控制項:

 例:for (int i = 0 ; i <100; i++) {

        UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(i%4*80, 0, 79, 79)];

        l.text = @(i).stringValue;

        l.backgroundColor = [UIColor yellowColor];

        [self.view addSubview:l];

7.NSTimer 計時器:是用來顯示控制項運動的軌跡,

例:[NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(moveAction) userInfo:nil repeats:YES];

8、計算機步驟:

(1)搭建介面(一個文本輸入框 一個Label  五個按鈕)

(2).在加減乘除運算子按鈕的裡面去把使用者輸入的數字用一個全域變數儲存  並且用一個全域int類型的變數記錄加減乘除 清空文本輸入框

(3).在等於按鈕中 把使用者輸入的第二個數取出來用一個局部變數儲存,判斷之前儲存的int值到底是加減還是乘除 做相對應的運算 得到結果 

(4).把結果顯示到label中

#在藍懿學習iOS的日子#Day2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.