UI-Day02--昨日作業代碼(二)

來源:互聯網
上載者:User

標籤:

象棋

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2  3     // Override point for customization after application launch. 4  5     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 6  7     self.window.backgroundColor = [UIColor purpleColor]; 8  9     10 11     [self createLabels];12 13     14 15     [self.window makeKeyAndVisible];16 17     return YES;18 19 }20 21 -(void)createLabels{22 23     24 25     NSArray * array = @[@"車",@"馬",@"相",@"王",@"後",@"相",@"馬",@"車"];26 27     28 29     for (int i = 0; i < 8; i++) {30 31         for (int j = 0; j < 8; j++) {32 33             34 35             //0 8036 37             UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(j*40, i*40+80, 40, 40)];38 39             40 41             //設定label背景色42 43             if ((i + j)%2 == 0) {44 45                 label.backgroundColor = [UIColor blackColor];46 47             }else{48 49                 50 51                 label.backgroundColor = [UIColor whiteColor];52 53             }54 55             56 57             //顯示的文字58 59             if (i == 0 || i == 7) {60 61                 //j 0--762 63                 label.text = array[j];64 65             }66 67             if (i == 1 || i == 6) {68 69                 label.text = @"兵";70 71             }72 73             74 75             //設定字型顏色76 77             if (i == 0 || i == 1) {78 79                 label.textColor = [UIColor redColor];80 81             }82 83             if (i == 6 || i == 7) {84 85                 label.textColor = [UIColor yellowColor];86 87             }88 89             label.textAlignment = NSTextAlignmentCenter;90 91             label.adjustsFontSizeToFitWidth = YES;92 93             [self.window addSubview:label];94 95         }96 97     }98 99 }

 

 

 

 

 

九九乘法

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2  3      4  5     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 6  7     self.window.backgroundColor = [UIColor whiteColor]; 8  9     10 11     [self nineLabels];12 13     14 15     [self.window makeKeyAndVisible];16 17     return YES;18 19 }20 21 -(void)nineLabels{22 23     24 25     for (int i = 1; i <= 9; i++) {26 27         for (int j = 1; j <= i; j++) {28 29             30 31             // i  描述 y座標32 33             // j  描述 x座標34 35             36 37             //寬度 32 空隙 2  高度 2038 39             UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake((j-1)*(32 + 2), (i - 1)*(20 + 2)+80, 32, 20)];40 41             label.backgroundColor = [UIColor grayColor];42 43             label.text = [NSString stringWithFormat:@"%d*%d=%d",j,i,j*i];44 45             label.textColor = [UIColor greenColor];46 47             //字型根據label的寬度改變大小48 49             label.adjustsFontSizeToFitWidth = YES;50 51             //label根據字型改變寬高52 53 //            [label sizeToFit];54 55             56 57             [self.window addSubview:label];58 59         }60 61     }62 63 }

 

UI-Day02--昨日作業代碼(二)

聯繫我們

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