zoukankan      html  css  js  c++  java
  • 根据输入的个数,打印每行做多输出3个的for循环

    #define Screen_width  [[UIScreen mainScreen] bounds].size.width

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        //要显示的个数

        int How = 11;

    //    要显示的列数

        int lie = 4;

    //    中间的间隔

        int jiange = 10;

        //每行最多3个,根据个数看需要显示几行

        int row;

        if (How%lie>0) {

            row = How/lie+1;

            

        }else{

            row = How/lie;

        }

        //   根据输入的个数打印一个3列的数据    外控制行  内控制列

        int xZhou ;

        int yZhou ;

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

            yZhou = (Screen_width-(lie+1)*jiange)/lie*i+i*jiange+jiange;

            

            for(int y = 0; y< lie; y++){

                xZhou = (Screen_width-(lie+1)*jiange)/lie*y+y*jiange+jiange;

                

                if(i*lie+y+1 == How){

                    break;

                }else{

                    

                    printf("x轴:%d   y轴:%d",xZhou,yZhou);

                    UIButton *addPhotoButton = [[UIButton alloc]initWithFrame:CGRectMake(xZhou, yZhou, (Screen_width-(lie+1)*jiange)/lie, (Screen_width-(lie+1)*jiange)/lie)];

                    addPhotoButton.backgroundColor = [UIColor greenColor];

                    [self.view addSubview:addPhotoButton];

                    printf("*");

                }

                

            }

            printf(" ");

        }

        

        // Do any additional setup after loading the view, typically from a nib.

    }

  • 相关阅读:
    Java学习笔记day01
    对有序数组进行二分查找(折半查找)
    对数组进行冒泡排序
    LeetCode #344. Reverse String
    LeetCode #292. Nim Game
    LeetCode #258. Add Digits
    Android DiskLruCache完全解析,硬盘缓存的最佳方案
    Android源码解析——LruCache
    Messenger与AIDL的异同
    Android应用层View绘制流程与源码分析
  • 原文地址:https://www.cnblogs.com/AlienY/p/4676887.html
Copyright © 2011-2022 走看看