我是编码的新手,非常感谢你的帮助。我到处搜索我的问题,但找不到对我有意义的问题。这是我的代码(错误位置注明)。提前谢谢!
import UIKit
import Firebase
class UserVC: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
@IBOutlet weak var userImagePicker: UIButton!
@IBOutlet weak var completeSignUpBtn: UIButton!
var userUid: String!
var emailField: String!
var passwordField: String!
var imagePicker: UIImagePickerController!
var imageSelected = false
override func viewDidLoad() {
super.viewDidLoad()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
userImagePicker.image = image **//error here**
imageSelected = true
}else {
print("image wasn't selected")
}
imagePicker.dismiss(animated: true, completion: nil)
}
@IBAction func completeAccount (_ sender: Any){
Auth.auth().createUser(withEmail: emailField, password: passwordField, completion:
{(user, error) in
if error != nil {
print(error)
}else{
if let user = user {
self.userUid = user.uid
}
}
})
}
@IBAction func selectedImagePicker(_ sender: Any){
present (imagePicker, animated: true, completion: nil)
}
@IBAction func cancel (_ sender: AnyObject){
dismiss (animated: true, completion: nil)
}
}
答案 0 :(得分:1)
您无法直接将图像分配给UIButton。按钮有不同的方法来设置图像。这是设置按钮图像的快速3示例代码。
let playButton = UIButton(type: .custom)
playButton.setImage(UIImage(named: "play.png"), for: .normal)
所以试试这个
userImagePicker.setImage(image,for:.normal)