swift UIImagePickerController 스위프트 이미지피커컨트롤러 사진 불러오기 



//

//  SampleData.swift

//  TableViewAI

//

//  Created by stayfoolish on 20/11/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import Foundation


struct Sample {

    let title: String

    let description: String

    let image: String

}


struct SampleData {

    let samples = [

        Sample(title: "Photo Object Detection", description: "불러온 이미지에 사물 인식", image: "ic_photo"),

        Sample(title: "Real Time Object Detection", description: "실시간으로 카메라에 보이는 사물 인식", image: "ic_camera"),

        Sample(title: "Facial Analysis", description: "사람 얼굴로부터 나이, 성별, 감정 추측", image: "ic_emotion")

    ]

}



//

//  MainFeatureCell.swift

//  TableViewAI

//

//  Created by stayfoolish on 20/11/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import UIKit


class MainFeatureCell: UITableViewCell {


    @IBOutlet var featureImageView: UIImageView!

    @IBOutlet var titleLabel: UILabel!

    @IBOutlet var descriptionLabel: UILabel!

   

}


//

//  MainViewController.swift

//  TableViewAI

//

//  Created by stayfoolish on 20/11/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import UIKit


class MainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {


    @IBOutlet var tableView: UITableView!

    

    let sampleData = SampleData()

    

    override func viewDidLoad() {

        super.viewDidLoad()


        // Do any additional setup after loading the view.

        self.tableView.dataSource = self

        self.tableView.delegate = self 

        self.tableView.tableFooterView = UIView(frame: .zero)

    }

    

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)

        

        self.navigationController?.navigationBar.prefersLargeTitles = true

        

    }

    

    override func viewWillDisappear(_ animated: Bool) {

        super.viewWillDisappear(animated)

        

        self.navigationController?.navigationBar.prefersLargeTitles = false

    }

    

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return self.sampleData.samples.count

    }

    

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "mainFeatureCell", for: indexPath) as! MainFeatureCell

        

    let sample = self.sampleData.samples[indexPath.row]

        

        cell.titleLabel.text = sample.title

        cell.descriptionLabel.text = sample.description

        cell.imageView?.image = UIImage(named: sample.image)

        return cell

    }


    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        tableView.deselectRow(at: indexPath, animated: true)

        switch indexPath.row {

        case 0: self.performSegue(withIdentifier: "photoObjectDetection", sender: nil)

        case 1: self.performSegue(withIdentifier: "realTimeObjectDetection", sender: nil)

        case 2: self.performSegue(withIdentifier: "facialAnalysis", sender: nil)

        default:

            return

        }

    }


}


//

//  ObjectDetectinoViewController.swift

//  TableViewAI

//

//  Created by stayfoolish on 21/11/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import UIKit


class ObjectDetectinoViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {


    @IBOutlet var selectedImageView: UIImageView!

    override func viewDidLoad() {

        super.viewDidLoad()


        // Do any additional setup after loading the view.

    }

    

    @IBAction func addPhoto(_ sender: UIBarButtonItem) {

        let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

        

        let importFromAlbum = UIAlertAction(title: "앨범에서 가져오기", style: .default) { _ in

            let picker = UIImagePickerController()

            picker.delegate = self

            picker.sourceType = .savedPhotosAlbum

            picker.allowsEditing = true

            self.present(picker, animated:  true, completion: nil )

        }

        let takePhoto = UIAlertAction(title: "카메라로 찍기", style: .default) { _  in

            let picker = UIImagePickerController()

            picker.delegate = self

            picker.sourceType = .camera

            picker.cameraCaptureMode = .photo

            picker.allowsEditing = true

            self.present(picker, animated:  true, completion: nil )

        }

        let cancel = UIAlertAction(title: "취소", style: .cancel)

        

        actionSheet.addAction(importFromAlbum)

        actionSheet.addAction(takePhoto)

        actionSheet.addAction(cancel)

        

        self.present(actionSheet, animated: true, completion: nil)

        

    }

    

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        picker.dismiss(animated: true)

        if let uiImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {

            self.selectedImageView.image = uiImage

            

        }

    }

    

}







+ Recent posts