Last active
August 6, 2016 12:59
-
-
Save tkc/68f13ff0de2203f93a92d227b596a05f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class CameraSandBox: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{ | |
var button: UIButton! | |
private var myImageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
button = UIButton(frame: CGRectMake(0, 0,100, 100)) | |
button.backgroundColor = UIColor.redColor() | |
button.layer.cornerRadius = 50.0 | |
button.layer.position = CGPointMake(self.view.frame.width/2, self.view.frame.height-150) | |
button.setTitle("+", forState: .Normal) | |
button.setTitleColor(UIColor.whiteColor(), forState: .Normal) | |
button.addTarget(self, action: #selector(self.setLocation(_:)), forControlEvents: .TouchUpInside) | |
self.view.addSubview(button) | |
} | |
func setLocation(sender: UIButton){ | |
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){ | |
let imagePickerController = UIImagePickerController() | |
imagePickerController.sourceType = .PhotoLibrary | |
imagePickerController.allowsEditing = true | |
imagePickerController.delegate = self | |
presentViewController(imagePickerController, animated: true, completion: nil) | |
} | |
} | |
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { | |
if let image = info[UIImagePickerControllerEditedImage] { | |
self.myImageView=UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) | |
self.myImageView.layer.position = CGPoint(x: self.view.frame.width/2, y:self.view.frame.height/2) | |
self.myImageView.contentMode = UIViewContentMode.ScaleAspectFit | |
self.myImageView.image = image as? UIImage | |
self.view.addSubview(self.myImageView!) | |
} | |
picker.dismissViewControllerAnimated(true, completion: nil) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment