Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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
我想在ios中使用for循环,根据图像数、多行和两列对齐图像视图_Ios_For Loop_Uiimageview - Fatal编程技术网

我想在ios中使用for循环,根据图像数、多行和两列对齐图像视图

我想在ios中使用for循环,根据图像数、多行和两列对齐图像视图,ios,for-loop,uiimageview,Ios,For Loop,Uiimageview,添加uiimageview两列多行。例如,没有图像3,则第一行有两个图像已填充,第二行有一个图像需要填充 CGFloat marginX = self.view.frame.size.width *0.45; CGFloat marginY = self.view.frame.size.height * 0.12; CGRect ImageFrame = CGRectMake(self.view.frame.size.width * 0.05, self.view.frame.size.heig

添加uiimageview两列多行。例如,没有图像3,则第一行有两个图像已填充,第二行有一个图像需要填充

CGFloat marginX = self.view.frame.size.width *0.45;
CGFloat marginY = self.view.frame.size.height * 0.12;
CGRect ImageFrame = CGRectMake(self.view.frame.size.width * 0.05, self.view.frame.size.height *0.2, self.view.frame.size.width *0.4, self.view.frame.size.height * 0.1);


if(isiPad)
{


    for(int i=1;i<no_ofitems;i++)
    {
       //int rows = i/2;

        int columns = i %2;

      //  for(int j=-1;j<rows;j++)
      //  {
      //
            for (int k=0;k<=columns;k++)
            {

                UIImageView *InApp_imageview=[[UIImageView alloc]initWithFrame:ImageFrame];

                [InApp_imageview setImage:[UIImage imageNamed:@"buttonbg.png"]];

                [self.view addSubview:InApp_imageview];
                ImageFrame.origin.x += marginX;




            }

            ImageFrame.origin.x = self.view.frame.size.width * 0.05;
            ImageFrame.origin.y += marginY;
       // }


    }
CGFloat-marginX=self.view.frame.size.width*0.45;
CGFloat marginY=self.view.frame.size.height*0.12;
CGRect ImageFrame=CGRectMake(self.view.frame.size.width*0.05,self.view.frame.size.height*0.2,self.view.frame.size.width*0.4,self.view.frame.size.height*0.1);
如果(isiPad)
{

对于(inti=1;iChoice-1

定制自己

有计划地创造

// initially set the x and y frames as zero 
x=0;
y=0;

 // crete the scrollview for the purpose of scroll actually we dont know how much data will comes.
 UIScrollView  *scroller=[[UIScrollView alloc]init];
          scroller.frame=CGRectMake(20.0, 10.0, 250.0, 250.0); // customize the frame

scroller.delegate=self;

[self.view addSubview:scroller];
// set the  ContentSize based on array count * visible of Items per row * some heights
[scroller setContentSize:(CGSizeMake(300,(([no_ofitems count]+2-1)/2)*20))];


for (int i=1; i<[no_ofitems count]+1; i++)
{   
    // using modulo for split the items when its reach to limit
    if (x%2==0)
    {
        x=0;
        y++; // increase the y frame based on split
    }

    UIImageView * InApp_imageview =[[UIImageView alloc]initWithFrame:CGRectMake(x*60, y*60, 50, 50)];  // here its automatically set the frame for each height

      [InApp_imageview setImage:[UIImage imageNamed:@"buttonbg.png"]];
     InApp_imageview.userInteractionEnabled=YES;

            InApp_imageview.contentMode = UIViewContentModeScaleToFill;
            InApp_imageview.tag=i-1;
    [scroller addSubview: InApp_imageview];
    InApp_imageview =nil;
    x++; // increase the each x frame based on array count
}
//最初将x和y帧设置为零
x=0;
y=0;
//我们不知道会有多少数据。
UIScrollView*滚动器=[[UIScrollView alloc]init];
scroller.frame=CGRectMake(20.0,10.0,250.0,250.0);//自定义框架
scroller.delegate=self;
[self.view addSubview:scroller];
//根据数组计数*每行项目可见*某些高度设置ContentSize
[滚动条设置内容大小:(CGSizeMake(300,([no_of Items count]+2-1)/2)*20));

对于(int i=1;i@Anbu.Karthik)我没有得到it@divyaswaminathan-在哪一部分你不明白如果你需要支持,问我,我肯定会解释我的code@divyaswaminathan--当然,安布,我现在明白了。