UIAlert アクションシート

イメージ 1


//
//  ViewController.swift
//  nonSample13
//
//  Created by non on 2015/03/21.
//  Copyright (c) 2015 non. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    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.
    }
    
    @IBAction func nonbtn(sender: UIButton) {
        //アクションシート作成
        var nonalertController = UIAlertController(
            title:"タイトル",
            message:"メッセージ",
            preferredStyle:UIAlertControllerStyle.ActionSheet)
        
        //アクションシート1追加
        nonalertController.addAction(UIAlertAction(
            title:"アクション1",
            style:.Default,
            handler:{action in self.myActionOne()}))
   
        //アクションシート2追加
        nonalertController.addAction(UIAlertAction(
            title:"アクション2",
            style:.Default,
            handler:{action in self.myActionTwo()}))
        
        //OKボタンを追加
        nonalertController.addAction(UIAlertAction(
            title:"OK",
            style:.Default,
            handler: { action in self.myOK() }
            ))
        
        //削除ボタンを追加
        nonalertController.addAction(UIAlertAction(
            title:"削除",
            style:.Destructive,
            handler: { action in self.myDel()}
            ))
        
        //Cancelボタンを追加
        nonalertController.addAction(UIAlertAction(
            title:"Cancel",
            style:.Cancel,
            handler: {action in self.myCancel() }
            ))
        
        //アラート表示
        presentViewController(nonalertController,animated:true, completion: nil)
    }
    
    func myActionOne(){
        println("Action1")
    }
    func myActionTwo(){
        println("Action2")
    }
    func myOK() {
       println("OK")
    }
    func myDel(){
        println("delete")
    }
    
    func myCancel(){
        println("Cancel")
    }
    

}



UIAlertController アラート


イメージ 1
イメージ 2

    @IBAction func nonbtn(sender: UIButton) {
        //アラート
        var nonalert = UIAlertController(
            title:"タイトル",
            message:"メッセージ",
            preferredStyle:UIAlertControllerStyle.Alert)
        
        //アラート表示
        presentViewController(nonalert,animated:true, completion: nil)

    }

OK/Cancel アラート
イメージ 3


UIAlertActionStyle.Default .Default  OKボタン
UIAlertActionStyle.Cancel .Cancel  Cancelボタン

UIAlertActionStyle.Destructive 削除ボタン

イメージ 4

    @IBAction func nonbtn(sender: UIButton) {
        //アラート
        var nonalert = UIAlertController(
            title:"タイトル",
            message:"メッセージ",
            preferredStyle:UIAlertControllerStyle.Alert)
        
        //OKボタンを追加
        nonalert.addAction(UIAlertAction(
            title:"OK",
            style:.Default,
            handler: { action in self.myOK() }
            ))
        
        //Cancelボタンを追加
        nonalert.addAction(UIAlertAction(
            title:"Cancel",
            style:.Cancel,
            handler: {action in self.myCancel() }
            ))
        
        //アラート表示
        presentViewController(nonalert,animated:true, completion: nil)
    }
    
    func myOK() {
       println("OK")
    }
    
    func myCancel(){
        println("Cancel")

    }




削除ボタンのアラート
イメージ 5

イメージ 6


    @IBAction func delbtn(sender: UIButton) {
        var nondelalert = UIAlertController(
            title:"タイトル",
            message:"メッセージ",
            preferredStyle:.Alert)
        
        //削除ボタンを追加
        nondelalert.addAction(UIAlertAction(
            title:"削除",
            style:.Destructive,
            handler: { action in self.myDel() }
            ))
        
        //アラート表示
        presentViewController(nondelalert,animated:true, completion: nil)
    }
    
    func myDel(){
        println("Delete")

    }


UIDatePicker 日付

**IBで設定する**
Mode 表示モード
Interval 分の刻み幅
Date デフォルトの日付
Minimum Date 選択できる一番古い日付
Maximum Date 選択できる一番新しい日付

***Programで設定する***
UIDatePickerMode.DateAndTime 月、時、分を表示
UIDatePickerMode.Date 年、月、日を表示
UIDatePickerMode.Time 時、分を表示
UIDatePickerMode.CountDownTimer 時、分を表示。タイマー用

★年、月、日を表示する
nonpicker.datePickerMode = UIDatePickerMode.Date

★2015年5月5日を表示
nonpicker.datePickerMode = UIDatePickerMode.Date
let df = NSDateFormatter()
df.dateFormat = “yyyy/MM/dd HH:mm:ss”
nonpicker.date = df.dateFormString(“2015/05/05 10:05:18”)!

★分の刻み幅を5分に設定
nonpicker.datePickerMode = UIDatePickerMode.CountDownTimer
nonpicker.minuteInterval = 5

★2014/1/1から2015/12/31範囲選択可能
nonpicker.datePickerMode = UIDatePickerMode.Date
df.dataFormat = “yyyy/MM/dd”
nonPicker.minimumDate = df.dateFormatString(“2014/01/01”)
nonPicker.maximumDate = df.dateFormatString(“2015/12/31”)

★現在の時刻
var sysdate = NSDate()
//時分秒のフォーマッターを作る
var df = NSDateFormatter()
//時刻をフォーマッターの書式で文字列に変換する
df.dateFormat = “HH:mm:ss”
var datestr = df.stringFromDate(now)
//出力
println(datestr)


イメージ 1

イメージ 2

イメージ 3

イメージ 4
イメージ 5

イメージ 6

//
//  ViewController.swift
//  nonSample13
//
//  Created by non on 2015/03/21.
//  Copyright (c) 2015 non. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    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.
    }
    
    //Date Picker
    @IBAction func nonpickerChange(sender: UIDatePicker) {
        let df = NSDateFormatter()
        df.dateFormat = ("yyyy/MM/dd HH:mm:ss")
        var selectdate = df.stringFromDate(sender.date)
        println("選択した日付は\(selectdate)です")
        
    }
    
}
UITextView 長いテキストを表示したり、入力させる

***Programで設定する***
★値を表示
txtview1.text = “kapibara-san"

★文字の色を青にする
txtview1.textColor = UIColor.blueColor()

★背景色を水色にする
txtview1.backgroundColor =  UIColor.cyanColor()

★フォント
txtview1.font = UIFont(name:”AmericanTypewriter”, size: 20)

★右寄せで表示
txtview1.textAlignment = NSTextAlignment.Right

★編集可能にする
txtview1.editable = true

★URLキーボードの種類を設定する
txtview1.keyboardType = UIKeyboardType.URL

★リターンキーをSendにする
txtview1.returnKeyType = UIReturnKey.Send

★キーボードを消す

txtview1.resignFirstResponder()

イメージ 1

イメージ 2

イメージ 3

イメージ 4

実行↓

イメージ 5


デバッグ出力結果

イメージ 6







UITextField テキスト入力

***Programで設定する***
★kapibara-sanを表示する
txt1.txt = “kapibara-san”

★プレスホルダー
txt1.placeholder = “文字を入力してください”

★配置を設定する
txt1.textAlignment = NSTextAlignment.Center

中央 NSTextAlignment.Center
左寄せ NSTextAlignment.Left
右寄せ NSTextAlignment.Right

★文字色を青にする
txt1.textColor = UIColor.blueColor()

★背景色を水色にする
txt1.backgroundColor = UIColor.cyanColor()

★太字フォント14
txt1.font = UIFont.boldSystemFontOfSize(14)

★キーボードの種類を設定する
txt1.keyboardType = UIKeyboardType.URL

デフォルト UIKeyboardType.Default
英字入力用 UIKeyboardType.ASCIICapable
URL入力用 UIKeyboardType.URL
メールアドレス入力用 UIKeyboardType.EmailAddress
数字入力用 UIKeyboardType.NumberPad
電話番号入力用 UIKeyboardType.PhonePad

★リターンキーの設定
txt1.returnKeyType = UIReturnKeyType.Send

returnはUIReturnKeyType.Default
UIReturnKeyType.Go
UIReturnKeyType.Join
UIReturnKeyType.Next
UIReturnKeyType.Search
UIReturnKeyType.Send
UIReturnKeyType.Done

★キーボードを消す
txt1.resignFirstResponder()
イメージ 1

イメージ 2

イメージ 3


イメージ 4

イメージ 5


イメージ 6
イメージ 7



//
//  ViewController.swift
//  nonSample13
//
//  Created by non on 2015/03/21.
//  Copyright (c) 2015 non. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    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.
    }
    
    @IBAction func txt1(sender: UITextField) {
        println("値は\(sender.text)")
    }

}
UISwitch スイッチ

**IBで設定する**
★Switch
State On/Offの状態
On Tint Onの背景色
Thumb Tint つまみの色

**Programで設定する**
★スイッチをOnにする
nonSwitch.on = true
★Onの時の背景色を設定する
nonSwitch.onTintColor = UIColor.redColor()

★つまみの色黄色にする
nonSwitch.thumbTintClolor = UIColor.yellowColor()


//
//  ViewController.swift
//  nonSample13
//
//  Created by non on 2015/03/21.
//  Copyright (c) 2015 non. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    

    @IBOutlet weak var nonSwitch: UISwitch!
    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.
    }
    
    
    @IBAction func changeSwitch(sender: UISwitch) {
        
        if sender.on == true
        {
            println("スイッチOn")
        }else{
            println("スイッチoff")
        }
    }
}

イメージ 1

イメージ 2

イメージ 3

イメージ 4



UIButton ボタン


**IBで設定する**
★Type
Custom 自分でデザインしたボタンが作れる
System 標準ボタン
Detail Disclosure 詳細画面に移行するときのiボタン
Info Light iボタン
Info Dark iボタン
Add Contact 追加+ボタン

★State Config
Default 通常の表示
Highlighted ボタンにタッチ中の表示
Selected 選択中の表示
Disabled ボタンが無効の時の表示

**Programで設定する**
ボタンに kapibara-sanだよ と表示する
nonBtn.setTitle(“kapibara-sanだよ”,forState: UIControlState.Normal)

★ボタンの状態
UIControlState.Normal 通常の状態
UIControlState.Highlighted ボタンにタッチ中
UIControlState.Selected 選択中
UIControlState.Disabled 無効の時

★選択状態
nonBtn.selected = true
★ボタンを無効にする
nonBtn.enabled = false


イメージ 1

イメージ 2




ジャンプバー

    //FIXME:未完成な部分
    //TODO:気になるところ
    //MARK:分割線

イメージ 1