Upload Photo Seperti Instagram Di Swift

Upload, browse atau picker photo dari galery atau camera sering kali digunakan dalam beberapa aplikasi. Mari belajar untuk membuat tampilan upload photo seperti aplikasi instagram menggunakan Library YPImagePicker.

– Buka project di Terminal
– Buka Podfile -> open a xcode Podfile
– Tambahkan pada Podfile -> pod ‘YPImagePicker’
– Install framework -> pod install
– Buat baru UIViewController

UIViewController
UIViewController

– Tambahkan 1 buah button
– Tambah 1 File Cocoa Touch Class, pickerViewController.swift
– Kembali lagi ke main storyboard pada UIViewController -> ubah class “pickerViewController”

Class "pickerViewController"
Class “pickerViewController”

– Pada ViewController Source -> tambahkan import YPImagePicker
– Ketikkan code seperti berikut :

import UIKit
import YPImagePicker

class pickerViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func goUpload(_ sender: Any) {
        var config = YPImagePickerConfiguration()
        config.library.mediaType = .photo
        config.library.onlySquare = false
        config.onlySquareImagesFromCamera = true
        config.targetImageSize = .original
        config.usesFrontCamera = true
        config.showsFilters = true
        config.shouldSaveNewPicturesToAlbum = true
        config.albumName = "Sewa Mobil"
        config.screens = [.library, .photo]
        config.startOnScreen = .library
        config.video.recordingTimeLimit = 10
        config.video.libraryTimeLimit = 20
        config.showsCrop = .rectangle(ratio: (16/9))
        config.wordings.libraryTitle = "Gallery"
        config.hidesStatusBar = false
        config.library.maxNumberOfItems = 5
        config.library.minNumberOfItems = 1
        config.library.numberOfItemsInRow = 3
        config.library.spacingBetweenItems = 2
        config.isScrollToChangeModesEnabled = false

        let picker = YPImagePicker(configuration: config)
        present(picker, animated: true, completion: nil)
    }
}

– Tambahkan code pada info.plist seperti berikut :

<key>NSCameraUsageDescription</key>
<string>Camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Libray</string>
<key>NSMicrophoneUsageDescription</key>
<string>Microphone</string>

Jalan project / aplikasi

Page Home
Page Home
Page Upload Seperti Instagram
Page Upload Seperti Instagram

Terima kasih. Happy Coding 🙂

Leave a Reply

Your email address will not be published.