如何通过编程将9个偶数图像添加到视图| Swift
我正在努力解决这个问题,希望能在代码方面找到任何帮助。 我试图以编程方式添加9个图像(3x3),这将覆盖我的整个UIView。 我的问题是,如何将我的UIVIEW划分为9个甚至是图像来覆盖所有这些,并且考虑到iPhone屏幕大小之间的不同。 我甚至不知道如何开始定制它,例如:如何通过编程将9个偶数图像添加到视图| Swift,swift,uiimageview,Swift,Uiimageview,我正在努力解决这个问题,希望能在代码方面找到任何帮助。 我试图以编程方式添加9个图像(3x3),这将覆盖我的整个UIView。 我的问题是,如何将我的UIVIEW划分为9个甚至是图像来覆盖所有这些,并且考虑到iPhone屏幕大小之间的不同。 我甚至不知道如何开始定制它,例如: firstImage.frame = CGRectMake(?,? ,200,200) secondImage.frame = CGRectMake(?,?, 200,200) 您可以将view.fram
firstImage.frame = CGRectMake(?,? ,200,200)
secondImage.frame = CGRectMake(?,?, 200,200)
您可以将
view.frame
划分为网格,并在特定位置添加UIImageView
作为子视图。图像位于UIImage数组中
func create(){
//Divide the screen height and width /3 because 3*3
var height = self.view.frame.height/3
var width = self.view.frame.width/3
//Add your images
var imageArray:[UIImage] = [firstImage, secondImage]
var count = 0
for i in 0...2{
for j in 0...2{
//Add a subview at the position
var subview = UIImageView(frame: CGRectMake(width*CGFloat(j), height*CGFloat(i), width, height))
subview.image = imageArray[count]
self.view.addSubview(subview)
count++
}
}
}
天啊,这是数学,但我自己从来没有想过。。。我要试试看