iOS App ๋งŒ๋“ค๊ธฐ #5 ๐Ÿฅ

longlivedrgnยท2022๋…„ 2์›” 18์ผ
0

App ๋งŒ๋“ค๊ธฐ

๋ชฉ๋ก ๋ณด๊ธฐ
5/7

์‚ฌ์ง„์•จ๋ฒ”, ์นด๋ฉ”๋ผ, ๋™์˜์ƒ์•จ๋ฒ”

mainstory ๋ณด๋“œ ์งœ๊ธฐ

์•ฑ์˜ ์นด๋ฉ”๋ผ ๊ถŒํ•œ์„ ์„ค์ •ํ•˜๊ธฐ

์ง์ ‘ info๋ฅผ ํ†ตํ•ด์„œ ๊ถŒํ•œ์„ ์„ค์ •ํ•˜๊ธฐ

์œ„์™€ ๊ฐ™์ด ์ฝ”๋“œ๊ฐ€ ์•„๋‹Œ UI ์‹œ์Šคํ…œ์—์„œ ์„ค์ •์„ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ์„ค์ •์„ ํ•  ์ˆ˜ ๋„ ์žˆ๋‹ค.

์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ๊ถŒํ•œ์„ ์„ค์ •ํ•˜๊ธฐ


์œ„์™€ ๊ฐ™์ด info์˜ source Code์— ๋“ค์–ด๊ฐ„๋‹ค.

์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

ViewController ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

viewDidLoad() ์ž‘์„ฑํ•˜๊ธฐ/ button click ์•ก์…˜์„ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ์ž‘์„ฑํ•ด๋ณด๊ธฐ

//
//  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)
    }

}


0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด