Skip to content

Commit

Permalink
UIKitを包括したアプリのサンプルコード
Browse files Browse the repository at this point in the history
  • Loading branch information
KYRIE MIYAJIMA authored and KYRIE MIYAJIMA committed Feb 17, 2015
0 parents commit 69bf400
Show file tree
Hide file tree
Showing 60 changed files with 2,728 additions and 0 deletions.
60 changes: 60 additions & 0 deletions UIActivityIndicatorVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// UIActivityIndicatorVC.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/13.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//

import UIKit

class UIActivityIndicatorViewController: UIViewController {

var myActivityIndicator: UIActivityIndicatorView!
var myButton:UIButton!

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

self.title = "UIActivityIndicator";
self.view.backgroundColor = UIColor.whiteColor();

myActivityIndicator = UIActivityIndicatorView();
myActivityIndicator.frame = CGRectMake(0, 0, 50, 50);
myActivityIndicator.center = self.view.center;
myActivityIndicator.hidesWhenStopped = false;
myActivityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
myActivityIndicator.startAnimating();
self.view.addSubview(myActivityIndicator);

myButton = UIButton(frame: CGRectMake(0, 0, 300, 50));
myButton.backgroundColor = UIColor.redColor();
myButton.setTitle("STOP", forState: .Normal);
myButton.setTitleColor(UIColor.whiteColor(), forState: .Normal);
myButton.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height-50);
myButton.addTarget(self, action: "onClick:", forControlEvents: .TouchUpInside);
self.view.addSubview(myButton);

}

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

func onClick(sender:UIButton){
let isAnimate:Bool = myActivityIndicator.isAnimating();

if isAnimate == true{
myActivityIndicator.stopAnimating();
myButton.setTitle("START", forState: .Normal);
myButton.backgroundColor = UIColor.greenColor();
}else{
myActivityIndicator.startAnimating();
myButton.setTitle("STOP", forState: .Normal);
myButton.backgroundColor = UIColor.redColor();
}
}

}


67 changes: 67 additions & 0 deletions UIAlertActionVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// UIAlertActionVC.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/16.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//

import UIKit

class UIAlertActionViewController: UIViewController {

var myLabel:UILabel = UILabel(frame: CGRectMake(0, 0, 300, 100));

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

self.title = "UIAlertAction";
self.view.backgroundColor = UIColor.whiteColor();

myLabel.textAlignment = NSTextAlignment.Center;
myLabel.layer.position = CGPoint(x: self.view.frame.width/2, y: 100);
myLabel.textColor = UIColor.blackColor();
self.view.addSubview(myLabel);

let myButton:UIButton = UIButton(frame: CGRectMake(0, 0, 200, 100));
myButton.setTitle("action!", forState: .Normal);
myButton.titleLabel?.textAlignment = NSTextAlignment.Center;
myButton.titleLabel?.textColor = UIColor.whiteColor();
myButton.layer.position = CGPointMake(self.view.frame.width/2, 200);
myButton.backgroundColor = UIColor.greenColor();
myButton.addTarget(self, action: Selector("onClick:"), forControlEvents: .TouchUpInside);
self.view.addSubview(myButton);
}

func onClick(sender:UIButton){

var myAlert = UIAlertController(title: "UIKitDemo", message: "メッセージ", preferredStyle: UIAlertControllerStyle.ActionSheet);


let myAction_1 = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) in self.myLabel.text = "Yes"})

let myAction_2 = UIAlertAction(title: "No", style: UIAlertActionStyle.Destructive, handler: {
(action: UIAlertAction!) in
self.myLabel.text = "No";
})

let myAction_3 = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: {
(action: UIAlertAction!) in
self.myLabel.text = "Cancel";
})

myAlert.addAction(myAction_1);
myAlert.addAction(myAction_2);
myAlert.addAction(myAction_3);

myAlert.popoverPresentationController?.sourceView = self.view;
myAlert.popoverPresentationController?.sourceRect = CGRectMake(100.0, 100.0, self.view.frame.width/2, 20.0);

self.presentViewController(myAlert, animated: true, completion: nil);

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning();
}
}
44 changes: 44 additions & 0 deletions UIBarButtonItemVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// UIBarButtonItemViewController.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/09.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//

import UIKit

class UIBarButtonItemViewController:UIViewController {

var myLeftButton:UIBarButtonItem!
var myRightButton:UIBarButtonItem!

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

self.title = "UIBarButtonItem";
self.view.backgroundColor = UIColor.whiteColor();
self.navigationController?.navigationBar;

myLeftButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "onClick:");
myLeftButton.tag = 1;

myRightButton = UIBarButtonItem(title: "RightButton", style: .Plain, target: self, action: "onClick:");
myRightButton.tag = 2;

//self.navigationItem.leftBarButtonItem = myLeftButton;
self.navigationItem.rightBarButtonItem = myLeftButton;
}

func onClick(sender: UIButton){
switch(sender.tag){
case 1:
self.view.backgroundColor = UIColor(red:1, green:0, blue:0, alpha:1);
case 2:
self.view.backgroundColor = UIColor(red:1, green:0.59, blue:0.11, alpha:1);
default:
println("Error");
break;
}
}
}
44 changes: 44 additions & 0 deletions UIDatePickerVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// UIDatePickerVC.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/13.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//

import UIKit

class UIDatePickerViewController: UIViewController, UIPickerViewDelegate {

var dateLabel:UILabel = UILabel(frame: CGRectMake(0, 0, 300, 100));

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

self.title = "UIDatePicker";
self.view.backgroundColor = UIColor.whiteColor();

//datePicker
var myDatePicker:UIDatePicker = UIDatePicker();
myDatePicker.frame = CGRectMake(0, self.view.frame.height/4, 0, 0);
myDatePicker.timeZone = NSTimeZone.localTimeZone();
myDatePicker.addTarget(self, action: "changePicker:", forControlEvents: .ValueChanged);
self.view.addSubview(myDatePicker);

//ラベル
dateLabel.layer.position = CGPoint(x: self.view.frame.width/2, y: 500);
dateLabel.textAlignment = NSTextAlignment.Center;
self.view.addSubview(dateLabel);
}

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

func changePicker(sender: UIDatePicker){
let myDateFormatter:NSDateFormatter = NSDateFormatter();
myDateFormatter.dateFormat = "yyyy/MM/dd hh:mm";
var mySelectedDate:NSString = myDateFormatter.stringFromDate(sender.date);
dateLabel.text = mySelectedDate;
}
}
9 changes: 9 additions & 0 deletions UIKitDemo.xcodeproj/UITabBarSecond.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// UITabBarSecond.swift
//
//
// Created by Kyrie Miyajima on 2015/02/09.
//
//

import Foundation
Loading

0 comments on commit 69bf400

Please sign in to comment.