laying out images in UIScrollView automatically

前端 未结 2 1934
温柔的废话
温柔的废话 2021-01-14 19:34

i have a list of images retrieved from xml i want to populate them to a uiscrollview in an order such that it will look like this.

1 2 3

4 5 6

7 8

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 20:21

    I think you probably want to wrap your loop in another loop, to get what I'm going to call a 2D loop:

    for (int row = 0; row < num_rows; row++) {
       for (int col = 0; col < num_cols; col++) {
            // code before
            zenButton2.frame = CGRectMake(origin x dependent on col,
                                          origin y dependent on row,
                                          width,
                                          height);
            // code after
       }
    }
    

    Where the x and y of the CGRectMake() are multiples of the width and height of your image times the row and column respectively. Hope that makes sense.

提交回复
热议问题