LoginSignup
14

More than 5 years have passed since last update.

Swift 学習メモ vol.01

Posted at

はじめに

Swiftを9月から始めました。
勉強したメモを書いていきます。

勉強で使ったもの

Swift - Photo Gallery App (StoryBoard + Actions & Outlets) pt. 1/5
http://youtu.be/ztIBNHOm35E
https://github.com/TDAbboud/PhotosGalleryApp

  • メモがわかりにくかったらここを参照してください。

今回の成果物

gif01.gif

画像ギャラリーを作るためのはじめの一歩といった感じです。

インタフェースをストリーボードに配置する

ViewControllerを配置する

img01.jpg

Navigation Controllerを配置する

img02.jpg

CollectionViewをPhotoCellとして定義する

img03.jpg

CollectionViewの中にImageViewを配置し、PhotoCellとして定義する

img04.jpg

ImageViewとfullscreenViewを関連付ける

img05.jpg

Showを選択する

NavigationItemをViewに配置する。

Screen Shot 2014-09-13 at 3.20.56 PM.png

UIImageViewをフルスクリーンで配置

img07.jpg

Coding

ViewPhotoクラスを作成

img08.jpg

ViewPortクラスをストリーボードで関連付けする

img09.jpg

配置したボタンをアクション接続する

img10.jpg

追加したコード

ViewPhoto.swift
import UIKit

class ViewPhoto: UIViewController {

    @IBAction func btnCancel(sender: AnyObject) {
        println("Cancel")

        self.navigationController?.popToRootViewControllerAnimated(true)
    }


    @IBAction func btnTrush(sender: AnyObject) {
        println("trush")
    }

    @IBAction func btnExport(sender: AnyObject) {
        println("Export")
    }

    @IBOutlet weak var ImgView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}

  1. ロートコントローラに戻る。

ViewControllerのコードと関連付けを行う。

img11.jpg

ViewPhoto.swift
import UIKit

let reuseIdentifier = "PhotoCell"

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

    @IBOutlet var collectionView: UICollectionView!

    @IBAction func btnCamera(sender: AnyObject) {
    }

    @IBAction func btnPhotoAlbum(sender: AnyObject) {
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // uicollectionViewDataSource method

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        return 1
    }

    // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell

        // modify the cell
        cell.backgroundColor = UIColor.redColor()

        return cell
    }


}  

今後に向けて

今回はpart1だけのみなので、今後もすすめていきます。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14