//每行显示三个
let imgCount: CGFloat = 3.0
//每个图片宽度
let imageWH = 100
//间隙
let padding = 5
//循环9次
for index in 0..<9{
//求余,用于X轴索引(每一行达到3的整数时,求余就是零)
let yu = CGFloat(index).truncatingRemainder(dividingBy: imgCount)
//X轴坐标
let X = yu* (imageWH + padding)
//y轴坐标(索引除以每行的个数,得到每行的y轴坐标)
let Y = CGFloat( index / Int(imgCount)) * (imageWH + Padding5)
let img = UIImageView.init(frame: CGRect(x: X, y: Y, width: imageWH, height: imageWH))
img.backgroundColor = UIColor.orang
bgImgView.addSubview(img)
}
网友评论