[相关信息:Xcode7.2 ; Swift2.0]
先在需要的位置拖入一个显示图片的Image View控件用于显示
添加调整完以后是下面这样的
然后把控件跟代码关联起来
为三个按钮添加单击事件
然后在代码的最上面为类添加两个继承
最后添加代码
@IBAction func 选择相片(sender: AnyObject) {
let _photo = UIImagePickerController()
_photo.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
_photo.delegate = self
self.presentViewController(_photo, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image:UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
相册图片.image = image
picker.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func 删除相片(sender: AnyObject) {
if let _ = 相册图片.image {
相册图片.image = nil
print("Photo is set nil")
}
}
@IBAction func 删除事件(sender: AnyObject) {
}
最后一个按钮的事件先不添加。
运行下看看效果吧👋👋👋