UIImageView计入SWIFT

时间:2014-10-16 11:09:33

标签: swift uiimage

全部,

我有这个

@IBOutlet weak var ImageViewMain: UIImageView!
@IBOutlet weak var ImageView1: UIImageView!
@IBOutlet weak var ImageView2: UIImageView!
@IBOutlet weak var ImageView3: UIImageView!
@IBOutlet weak var ImageView4: UIImageView!
@IBOutlet weak var ImageView5: UIImageView!
@IBOutlet weak var ImageView6: UIImageView!
@IBOutlet weak var ImageView7: UIImageView!
@IBOutlet weak var ImageView8: UIImageView!
@IBOutlet weak var ImageView9: UIImageView!

这些是在我的故事板中分配的。

我有这样的功能:

func Staffphotos(数量:Int) {

self.ImageView1.image = image
var division : CGFloat = (self.ImageView1.frame.size.width / 2.0)
self.ImageView1.layer.cornerRadius = division
self.ImageView1.clipsToBounds = true
self.ImageView1.layer.borderWidth = 2.0
self.ImageView1.layer.borderColor = colour.CGColor
self.view.addSubview(self.ImageView1)

}

这需要依赖于(quantity:int)运行x次。那么它应该按照(数量:int)填充槽的数量(imageView1-8)。

如何做到这一点的任何想法?

1 个答案:

答案 0 :(得分:0)

@IBOutlet weak var ImageViewMain: UIImageView!
@IBOutlet weak var ImageView1: UIImageView!
@IBOutlet weak var ImageView2: UIImageView!
@IBOutlet weak var ImageView3: UIImageView!
@IBOutlet weak var ImageView4: UIImageView!
@IBOutlet weak var ImageView5: UIImageView!
@IBOutlet weak var ImageView6: UIImageView!
@IBOutlet weak var ImageView7: UIImageView!
@IBOutlet weak var ImageView8: UIImageView!
@IBOutlet weak var ImageView9: UIImageView!

var arrayOfImages = [UIImageView]()
arrayOfImages.append(ImageView1)
arrayOfImages.append(ImageView2)
arrayOfImages.append(ImageView3)
arrayOfImages.append(ImageView4)
arrayOfImages.append(ImageView5)
arrayOfImages.append(ImageView6)
arrayOfImages.append(ImageView7)
arrayOfImages.append(ImageView8)
arrayOfImages.append(ImageView9)

func staffPhoto(imageView:UIImageView)
{
    imageView.image = image
    var division : CGFloat = (imageView.frame.size.width / 2.0)
    imageView.layer.cornerRadius = division
    imageView.clipsToBounds = true
    imageView.layer.borderWidth = 2.0
    imageView.layer.borderColor = colour.CGColor
    self.view.addSubview(imageView)
}

for var imageView in arrayOfImages
{
    staffPhoto(imageView)
}

让我知道这是否有效