标签:
象棋
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 80 36 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--7 62 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 高度 20 38 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 }
标签:
原文地址:http://www.cnblogs.com/IOS-BUDO/p/4775431.html