UI4

it2024-10-30  12

// // AppDelegate.m // UI4_LabelChess // // Created by zhangxueming on 15/6/29. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // [self showLabelChess]; [self printShow]; self.window.rootViewController = nil; self.window.backgroundColor = [UIColor whiteColor]; return YES; } - (void)showLabelChess { CGFloat width= self.window.frame.size.width/8; NSArray *textArray = @[@"車",@"马",@"象",@"王",@"后",@"象",@"马",@"車"]; for (int i=0; i<8; i++) { for(int j=0;j<8; j++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(j*width, i*width+20, width,width)]; if ((i+j)%2) { label.backgroundColor = [UIColor yellowColor]; } else { label.backgroundColor = [UIColor greenColor]; } if(i==0||i==7) { label.text = textArray[j]; label.textAlignment = NSTextAlignmentCenter; } if (i==1||i==6) { label.text = @"兵"; label.textAlignment = NSTextAlignmentCenter; } if (i==0||i==1) { label.textColor = [UIColor redColor]; } if (i==6||i==7) { label.textColor = [UIColor blueColor]; } [self.window addSubview:label]; } } } -(void)printShow { CGFloat length=self.window.frame.size.width/9; for(int i=0;i<9;i++) { for(int j=0;j<=i;j++) { UILabel *lable1 =[[UILabel alloc] initWithFrame:CGRectMake(j*length, i*length+20, length-1, length-1)]; lable1.text=[[NSString alloc]initWithFormat:@"%d*%d=%d", (i+1),(j+1),(i+1)*(j+1)]; lable1.backgroundColor=[UIColor blueColor]; lable1.adjustsFontSizeToFitWidth=YES; [self.window addSubview:lable1]; } } }

 

转载于:https://www.cnblogs.com/0515offer/p/4638323.html

最新回复(0)