gpt4 book ai didi

iphone - 如何计算 Item of Frame 在 iPhone 中的位置?

转载 作者:行者123 更新时间:2023-11-28 22:51:17 25 4
gpt4 key购买 nike

首先,我有一个用 UIView 绘制的项目。我想绘制 20 个项目,其中一行有 4 个项目,所以有 5 行。我的问题是如何找到或计算项目的所有位置。

最佳答案

假设是 iPhone:

const float itemWidth = 320.0 / 4;
const float itemHeight = 480.0 / 4;

for (int row = 0; row < 5; row++)
for (int col = 0; col < 4; col++)
{
CGRect frm = CGRectMake(col * itemWidth, row * itemHeight, itemWidth, itemHeight);
// frm contains the position and size of each element
}

需要针对 iPad 进行调整,或者如果您想要元素之间的填充。

关于iphone - 如何计算 Item of Frame 在 iPhone 中的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11932828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com