4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Xcode】右と左を交互に表示する案内アプリをざくっと作る

Last updated at Posted at 2016-04-23

はじめに

独学でプログラミング学び始めて約1年、業務でプログラム書き始めて2ヶ月、Swift始めて1ヶ月のSwifterです。
ちょっと古いですが、ネットでこんな記事がありました。
右か左かをランダムに表示するだけのiPadアプリに合計1億5000万円以上が支払われていた
参考:GIGAGINE

俺に作らせてくれ!といいたいところです。ランダムではないですが、タップするたび矢印の向きが変わるアプリを15分でざくっと作りました。
githubサンプル

arrow.gif

手順

  • 矢印画像を作る(SketchというAppがオススメです)
  • imageViewを配置
  • buttonを画面いっぱいに配置
  • タップするたびに画像を入れ替える

コード

こんな感じ

ViewController.swift
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var arrowImage: UIImageView!
    
    var isRight: Bool = true
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

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

    @IBAction func changeArrow(sender: AnyObject) {
        if isRight {
            self.arrowImage.image = UIImage(named: "left.png")
            isRight = false
        } else {
            self.arrowImage.image = UIImage(named: "right.png")
            isRight = true
        }
    }

}

if文のところはもっと簡単に書けそうですがこれくらいの処理ならこんな感じでよいかと。
これで1億5000万プレイヤー間違いなし!

4
3
0

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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?