我已经从图像库中被加载之后要被显示的四个不同的图像中,两个在顶部,两个在底部的正方形。
每个图像视图关联到其个人的按钮,即会使用进入用户库中相同的方法来进行摄像。
我如何使用四种不同的按钮,用同样的方法来显示在适当的位置装的形象呢?
我可以做一个模型来执行这种行为?
谢谢
@IBOutlet weak var topLeftImage: UIImageView!
@IBOutlet weak var topRightImage: UIImageView!
@IBOutlet weak var bottomLeftImage: UIImageView!
@IBOutlet weak var bottomRightImage: UIImageView!
@IBOutlet weak var topLeftButton: UIButton!
@IBOutlet weak var topRightButtom: UIButton!
@IBOutlet weak var bottomLeftButton: UIButton!
@IBOutlet weak var bottomRightButton: UIButton!
@IBAction func loadTopLeftImage(_ sender: Any) {
loadPhotoLibrary()
}
@IBAction func loadTopRightImage(_ sender: Any) {
loadPhotoLibrary()
}
@IBAction func loadBottomLeftImage(_ sender: Any) {
loadPhotoLibrary()
}
@IBAction func loadBottomRightImage(_ sender: Any) {
loadPhotoLibrary()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
topLeftImage.image = image
}
self.dismiss(animated: true, completion: nil)
}
func loadPhotoLibrary() {
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true)
}