์์ ๊ฐ์ด ์ฝ๋๊ฐ ์๋ UI ์์คํ ์์ ์ค์ ์ ํ ์ ์์ง๋ง, ์๋์ ๊ฐ์ด ์ฝ๋๋ฅผ ํตํด์ ์ค์ ์ ํ ์ ๋ ์๋ค.
์์ ๊ฐ์ด info์ source Code์ ๋ค์ด๊ฐ๋ค.
์์ ๊ฐ์ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
//
// ViewController.swift
// crack_app_5
//
// Created by ๊น์ฉ์ฌ on 2022/02/16.
//
import UIKit
import YPImagePicker
class ViewController: UIViewController {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var profileChangeBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// ๋๊ทธ๋๊ฒ ๋ง๋ค๊ธฐ!
profileImage.layer.cornerRadius = profileImage.frame.height / 2
profileChangeBtn.layer.cornerRadius = 10
// ์๋ ์ฐ๋ฆฌ๊ฐ ํ๋ ๋ฐฉ์๋๋ก ํ์ฌ ๋ฐ๊พธ๊ธฐ ๋ฒํผ์ ๋๊ณ ์์ action์ ๋ง๋ค ์ ์์ง๋ง, ์ง์ ์ด๋ ๊ฒ ์ฝ๋๋ฅผ ํตํด์ ๋ง๋ค์๋ ์๋ค!
self.profileChangeBtn.addTarget(self, action: #selector(onProfileChangeBtnClicked), for: .touchUpInside)
}
// ํ์ฌ ๋ณ๊ฒฝ ๋ฒํผ์ด ํด๋ฆญ๋์์ ๊ฒฝ์ฐ imagePicker๋ฅผ ๋์ฐ๊ฒ ํ๋ค.
@objc fileprivate func onProfileChangeBtnClicked(){
print("ViewController - onProfileChangeBtnClicked() called")
// ์นด๋ฉ๋ผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ธํ
(๊ตฌ์ฑ์ ๋ด๊ฐ ์ ํํ ์ ์๋ค.)
var config = YPImagePickerConfiguration()
config.screens = [.library]
let picker = YPImagePicker(configuration: config)
picker.didFinishPicking { [unowned picker] items, _ in
if let photo = items.singlePhoto {
print(photo.fromCamera) // Image source (camera or library)
print(photo.image) // Final image selected by the user
print(photo.originalImage) // original image selected by the user, unfiltered
print(photo.modifiedImage) // Transformed image, can be nil
print(photo.exifMeta) // Print exif meta data of original image.
// ํ์ฌ์ด๋ฏธ์ง๋ฅผ ๋ณ๊ฒฝํ๋ค.
self.profileImage.image = photo.image
}
// ์ฌ์ง ์ ํ์ฐฝ ๋ซ๊ธฐ
picker.dismiss(animated: true, completion: nil)
}
// ์ฌ์ง ์ ํ์ฐฝ ๋ณด์ฌ์ฃผ๊ธฐ
present(picker, animated: true, completion: nil)
}
}