Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
objective-C循环矩阵世界_Objective C_Iphone - Fatal编程技术网

objective-C循环矩阵世界

objective-C循环矩阵世界,objective-c,iphone,Objective C,Iphone,我想用label创建一个15*15的矩阵世界。如何循环行和列 UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 15, 15)]; myLabel.backgroundColor = [UIColor darkGrayColor]; [self.view addSubview:myLabel]; 假设您需要创建尺寸为18x98的50个标签 int x = 0; int y = 0;

我想用label创建一个15*15的矩阵世界。如何循环行和列

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 15, 15)];
myLabel.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:myLabel];

假设您需要创建尺寸为18x98的50个标签

    int x = 0;
    int y = 0;
    for (int i  = 0; i < 50; i++) {
        if (20 * x > self.view.frame.size.width) {
            x = 0;
            y++;
        }

        UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 * x, 100 * y, 18, 98)];
        myLabel.backgroundColor = [UIColor darkGrayColor];
        [self.view addSubview:myLabel];
        x++;
    }
intx=0;
int y=0;
对于(int i=0;i<50;i++){
如果(20*x>self.view.frame.size.width){
x=0;
y++;
}
UILabel*myLabel=[[UILabel alloc]initWithFrame:CGRectMake(20*x,100*y,18,98)];
myLabel.backgroundColor=[UIColor darkGrayColor];
[self.view addSubview:myLabel];
x++;
}