我可以选择与个人资料图像相同的图像,但是我不希望封面图像是其他图像。如果您需要屏幕截图,我可以为您提供一个,请帮助alias
let CoverButton: UIButton = {
let button = UIButton(type: .system)
button.setImage(#imageLiteral(resourceName: "profile_selected").withRenderingMode(.alwaysOriginal), for: .normal)
button.backgroundColor = UIColor.rgb(r: 188, g: 224, b: 253)
button.frame = CGRect(x: 0, y: 0, width: 375, height: 204)
return button
}()
let plusPhotoButton: UIButton = {
let button = UIButton(type: .system)
button.setImage(#imageLiteral(resourceName: "profile_selected").withRenderingMode(.alwaysOriginal), for: .normal)
button.backgroundColor = UIColor.rgb(r: 188, g: 224, b: 253)
button.addTarget(self, action: #selector(handlePlusPhoto), for: .touchUpInside)
button.frame = CGRect(x: 14, y: 231, width: 56, height: 56)
return button
}()
@objc func handlePlusPhoto() {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
present(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
plusPhotoButton.setImage(editedImage.withRenderingMode(.alwaysOriginal), for: .normal)
} else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
plusPhotoButton.setImage(originalImage.withRenderingMode(.alwaysOriginal), for: .normal)
}
plusPhotoButton.layer.cornerRadius = plusPhotoButton.frame.width/2
plusPhotoButton.layer.masksToBounds = true
dismis
答案 0 :(得分:1)
如果我对您的理解正确,那么问题是关于如何对同一视图控制器中的两个不同图像使用相同的imagePickerController?
查看此答案,希望对您有所帮助: https://stackoverflow.com/a/30657560/5858330
答案 1 :(得分:0)
因此,您需要将目标添加到CoverButton。 转到并将标签添加到您的两个按钮。在下面的此函数中,检查一下这种效果:
如果您不想将标签值发送给函数,请创建一个变量来保存标签的值,然后在下面的函数中进行检查。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if tagValue == 1 {
if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
coverButton.setImage(editedImage.withRenderingMode(.alwaysOriginal), for: .normal)
} else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
coverButton.setImage(originalImage.withRenderingMode(.alwaysOriginal), for: .normal)
}
coverButton.layer.cornerRadius = plusPhotoButton.frame.width/2
coverButton.layer.masksToBounds = true
} else if OTHERBUTTONTAG
"Do the same as above but for your plusPhotoButton"