LoginSignup
0
0

More than 5 years have passed since last update.

キミニキメタ

Last updated at Posted at 2017-11-16

初めてSwiftでアプリつくってみた

アプリ名「キミニキメタ」

アプリケーション目的:社内でシャイな人にも発言をしてもらうため、アプリに発言者を決めてもらう。
アプリ作成のヒント:おみくじアプリからヒントをもらう
最終目標:社員の似顔絵や写真などを入れて、ルーレットなどのアニメーションで決定シーンを作れたら楽しいかも。

下記のコードはまだボタンを押して名前をランダムに取得し、メッセージアラートに表示する、というのみの動作です。引き続き体裁を変更予定です。

背景画像、スタートボタン画像はイラストレーターで作成しEPS保存、フォトショップで最適化しjpeg保存して、 Xcodeの「Assets.xcasetts」に貼り付けて使用。

アラート
import UIKit

class ViewController: UIViewController {

    // ボタン押した時
    @IBAction func showAlert(sender: AnyObject) {

        // アラートを作る
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)

        // 配列の中からランダムで社員名取得、arc4random_uniformがランダム関数
        let luckArr = ["社員名1","社員名2","社員名3"]
        let r = arc4random_uniform(UInt32(luckArr.count))
        let randLuck = luckArr[Int(r)]

        // タイトル、メッセージのセット、指名後のメッセージの文言をここに入力
        alert.title = "君に決めた!"
        alert.message = randLuck

        // 閉じる為のボタン作成
        alert.addAction(
            UIAlertAction(title: "Let's talk", style: UIAlertActionStyle.default, handler: nil)
        )

        // アラートを表示
        self.present(alert, animated: true, completion: nil)

    }


    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.
    }


}

0
0
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
0
0