如何在swift中将相机中的图像设置为背景

时间:2014-11-14 10:04:32

标签: ios iphone swift

我正在设置一个背景,上面有我正在使用该应用的图片。

感谢

1 个答案:

答案 0 :(得分:0)

以下是一个例子,您可以帮助您:

var imagePicker = UIImagePickerController()
@IBOutlet var imagePreview : UIImageView

@IBAction func AddImageButton(sender : AnyObject) {
    imagePicker.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
    imagePicker.delegate = self
    self.presentModalViewController(imagePicker, animated: true)

}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) {
    let tempImage = editingInfo[UIImagePickerControllerOriginalImage] as UIImage
    imagePreview.image  = tempImage

    self.dismissModalViewControllerAnimated(true)

}

func imagePickerControllerDidCancel(picker: UIImagePickerController!) {

    self.dismissModalViewControllerAnimated(true)
}

这样您就可以为imageView设置图像。