2.2 9x9乘法表

- (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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容