我正为这件事苦苦挣扎,希望能在代码方面找到帮助。我正在尝试以编程的方式添加9张图片(3x3),这些图片将覆盖我的整个UIView。我的问题是,如何将我的UIView分割成9张甚至9张图片来覆盖所有这些,并考虑到iPhones屏幕大小之间的差异。我甚至不知道如何开始定制它,例如:
firstImage.frame = CGRectMake(?,? ,200,200)
secondImage.frame = CGRectMake(?,?, 200,200)发布于 2015-02-04 23:15:11
您可以将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++
}
}
}https://stackoverflow.com/questions/28333257
复制相似问题