Skip to content

Instantly share code, notes, and snippets.

View tdtsh's full-sized avatar

T.Hanazaki tdtsh

View GitHub Profile
@tdtsh
tdtsh / SomeVIewController.swift
Created February 11, 2016 13:14
Swift2 Facebook Popでフェードイン
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.blueColor()
// ラベル
var label: UILabel = UILabel()
@tdtsh
tdtsh / ViewController.swift
Created January 29, 2016 12:20
Swift2 でトーチをオンにする
let devices = AVCaptureDevice.devices()
for capDevice in devices {
if capDevice.position == AVCaptureDevicePosition.Back {
avDevice = capDevice as? AVCaptureDevice
}
}
// トーチオン
if avDevice.hasTorch
do {
@tdtsh
tdtsh / CameraViewController.swift
Last active January 22, 2016 09:50
UIViewをフェードイン
func renderView() {
/**
* ボタン
*/
let buttonTake = UIButton(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width - 50, height: 50))
buttonTake.backgroundColor = UIColor.init(colorLiteralRed: 0.3, green: 0.3, blue: 0.7, alpha: 0.5)
buttonTake.alpha = 0
buttonTake.layer.cornerRadius = 5.0
@tdtsh
tdtsh / CameraViewController.swift
Created January 21, 2016 15:35
Swift2 ボタンにラベルをのせ、NSLineBreakModeを指定
// 画面になにか重ねて表示する
func renderView() {
/**
* ボタン
*/
let buttonTake = UIButton(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width - 50, height: 50))
buttonTake.backgroundColor = UIColor.init(colorLiteralRed: 0.3, green: 0.3, blue: 0.7, alpha: 0.5)
buttonTake.layer.cornerRadius = 5.0
buttonTake.layer.masksToBounds = true
@tdtsh
tdtsh / CameraViewController.swift
Created January 19, 2016 15:10
Swift2 で UIButton
class CameraViewController: UIViewController {
...
func renderView() {
// ボタン作成
let buttonTake = UIButton(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width - 50, height: 50))
buttonTake.backgroundColor = UIColor.init(colorLiteralRed: 0.3, green: 0.3, blue: 0.7, alpha: 0.5)
// 角丸
buttonTake.layer.cornerRadius = 5.0
@tdtsh
tdtsh / ThirdViewController.swift
Created January 17, 2016 13:00
Swift2で NavigationController の子ウィンドウ閉じるとき2画面前に遷移させる
class ThirdViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 1つ前のViewControllerを遷移リストから削除
let parentIndex = (self.navigationController?.viewControllers.indexOf(self))! - 1
self.navigationController?.viewControllers.removeAtIndex(parentIndex)
}
@tdtsh
tdtsh / CameraViewController.swift
Created January 17, 2016 02:43
Swift2 でラベルを表示する
class CameraViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
// 角丸なLabelを作成
let labelHello: UILabel = UILabel(frame: CGRectMake(0, 0, 300, 40))
labelHello.layer.masksToBounds = true
labelHello.layer.cornerRadius = 5.0
@tdtsh
tdtsh / MasterViewController.swift
Created January 17, 2016 02:40
Swift2 NavigationController で画面遷移
class MasterViewController: UITableViewController {
...
func doCamera(sender: AnyObject) {
let cameraViewController = CameraViewController()
self.navigationController?.pushViewController(cameraViewController, animated: true)
}
}
</code>
@tdtsh
tdtsh / MasterViewController.swift
Last active January 17, 2016 02:34
Swift2 で Alert を表示
class MasterViewController: UITableViewController {
...
override func viewDidLoad() {
...
let cameraButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera, target: self, action: "doCamera:")
...
}
...
func doCamera(sender: UIButton) {
@tdtsh
tdtsh / MasterViewController.swift
Created January 17, 2016 02:28
Swift2 で NavigationBar の 右にボタンを複数追加
override func viewDidLoad() {
super.viewDidLoad()
// ボタン達
let addButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "insertNewObject:")
let cameraButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Camera, target: self, action: "insertNewObject:")
let myRightButtons = [addButton, cameraButton]
// テンプレはこうだった