程序化自动布局

时间:2018-03-26 05:43:45

标签: ios swift user-interface autolayout swift4

所以我有一个2d的UIImageViews数组,它显示一个游戏画面(就像棋盘但是各行/列)

目前我使用了以下自动布局代码:

int main()
{
    srand(time(0));

    //for (int times = 100; times < 1000; ++times) 
    int times = 1000000;
    {
        double pi_approx, probability;
        int number_of_coprime = 0;
        for (int i = 0; i < times; i++)
        {
            int num1, num2;
            num1 = rand() % times;
            num2 = rand() % times;
            if (__gcd(num1, num2) == 1) // increment if coprime !!
            {
                number_of_coprime++;
            }
        }
        probability = double(number_of_coprime) / double(times);
        pi_approx = sqrt(6 / probability);
        cout << pi_approx << endl;
    }

    return 0;
}

结果如下:

enter image description here

但我真正想要的是,无论水平尺寸如何,它始终保持在显示屏的中心(iPhone X),不会在侧面切掉一部分水平或留下大的间隙。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:-1)

我通常不会使用很多播客,但Snapkit会真正帮助您解决问题,使用更清晰,更具描述性的代码......

相关问题