- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createTable];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//创建九九乘法表
- (void)createTable{
//在外部去写一个宽高
float width = 90;
float height = 40;
for (int i = 1; i < 10; i ++)
{
for (int j = 1; j <= i; j++) {
//控制输出
//printf("%d * %d = %d ",i, j, i*j);
//再这里,由控制台输出改为用Label去做
UILabel *label = [[UILabel alloc] init];
//每个label 显示内容都是一个式子
label.text = [NSString stringWithFormat:@" %d * %d = %d",i,j,i*j];
label.frame = CGRectMake((j - 1 )* width ,(i - 1 +1) * height, width, height);
if ((i +j) %2 !=0){
label.backgroundColor = [UIColor redColor];
}
else {
label.backgroundColor = [UIColor yellowColor];
}
//添加到屏幕上显示
[self.view addSubview:label];
}
}
printf("\n");
}
@end
2.2 9x9乘法表
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- for (int i = 1; i <= 9; i++){for (int j =1; j<=i; j++){Co...
- 专业术语是相对日常用语而言的,一般指的某一行业的专有名称简介。大多数情况为该领域的专业人士所熟知,而专业术语在国际...