UIImageView的for循环 之田字格与曲线行LayOut

来源:互联网 发布:花生壳linux版客户端 编辑:程序博客网 时间:2024/04/29 14:55

for (int  i =0; i<9; i++) {

       UIImageView *image=  [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"ball_blue"]];

        //image.frame = CGRectMake(50, 300, 50, 50);

        [self.viewaddSubview:image];

        

       if (i<=2) {

            image.frame =CGRectMake(50+i*40,20,30,30);//150

        }

       elseif (i>2&&i<=5) {

            image.frame =CGRectMake(i*40-70,60,30,30);//120-20  100

        }

       else{

            image.frame =CGRectMake(i*40-190,100,30,30);//240-140  100


        }

    }

   for (int j =0; j<7; j++) {

       UIImageView *image=  [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"ball_red"]];

        [self.viewaddSubview:image];

        

       if (j>3) {

            image.frame =CGRectMake(50+j*40,320-20*j,30,30);//50

        }

       else{

            image.frame =CGRectMake(50+j*40,200+20*j,30,30);//50


        }

    }

另外一种方法 效率会高一些

    int i=0;

   for(i=0;i<25;i++){

       if (i==24) {

           break;

        }

        UIButton *ui = [UIButtonbuttonWithType:UIButtonTypeCustom];

        ui.frame=CGRectMake(10+i%5*60,i/5*60,50,50);

 cell.imageView.layer.masksToBounds = YES;//变圆

      cell.imageView.layer.cornerRadius = 20;

        ui.backgroundColor = [UIColorredColor];

        [self.viewaddSubview:ui];

    }




0 0