Skip to content

Commit

Permalink
Include swift version of ViewController in example
Browse files Browse the repository at this point in the history
  • Loading branch information
bvogelzang committed Jun 21, 2014
1 parent f6d2c6b commit 136c2d5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4593DA5E19560DB4006EB924 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4593DA5D19560DB4006EB924 /* ViewController.swift */; };
45B6529F176E3A440006F201 /* check.png in Resources */ = {isa = PBXBuildFile; fileRef = 45B6529B176E3A440006F201 /* check.png */; };
45B652A0176E3A440006F201 /* check@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 45B6529C176E3A440006F201 /* check@2x.png */; };
45B652A1176E3A440006F201 /* cross.png in Resources */ = {isa = PBXBuildFile; fileRef = 45B6529D176E3A440006F201 /* cross.png */; };
Expand All @@ -26,6 +27,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4593DA5D19560DB4006EB924 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
45B6529B176E3A440006F201 /* check.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = check.png; sourceTree = "<group>"; };
45B6529C176E3A440006F201 /* check@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "check@2x.png"; sourceTree = "<group>"; };
45B6529D176E3A440006F201 /* cross.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cross.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -98,6 +100,7 @@
45F7C649176D202700AE1301 /* MainStoryboard.storyboard */,
45F7C64C176D202700AE1301 /* ViewController.h */,
45F7C64D176D202700AE1301 /* ViewController.m */,
4593DA5D19560DB4006EB924 /* ViewController.swift */,
45DD2ABD1954C14B0028A5DB /* SevenSwitch.swift */,
45B6529B176E3A440006F201 /* check.png */,
45B6529C176E3A440006F201 /* check@2x.png */,
Expand Down Expand Up @@ -192,6 +195,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4593DA5E19560DB4006EB924 /* ViewController.swift in Sources */,
45DD2ABE1954C14B0028A5DB /* SevenSwitch.swift in Sources */,
45F7C63E176D202700AE1301 /* main.m in Sources */,
45F7C642176D202700AE1301 /* AppDelegate.m in Sources */,
Expand Down
1 change: 0 additions & 1 deletion SevenSwitchExample/SevenSwitchExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ - (void)viewDidLoad
ibSwitch.onTintColor = [UIColor colorWithRed:0.20f green:0.42f blue:0.86f alpha:1.00f];
ibSwitch.on = YES;


// this will create the switch with default dimensions, you'll still need to set the position though
// you also have the option to pass in a frame of any size you choose
SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];
Expand Down
61 changes: 61 additions & 0 deletions SevenSwitchExample/SevenSwitchExample/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// ViewController.swift
// SevenSwitchExample
//
// Created by Benjamin Vogelzang on 6/21/14.
// Copyright (c) 2014 Ben Vogelzang. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
@IBOutlet var ibSwitch: SevenSwitch

override func viewDidLoad() {
super.viewDidLoad()

ibSwitch.onTintColor = UIColor(red: 0.20, green: 0.42, blue: 0.86, alpha: 1)
ibSwitch.on = true

// this will create the switch with default dimensions, you'll still need to set the position though
// you also have the option to pass in a frame of any size you choose
let mySwitch = SevenSwitch(frame: CGRectZero)
mySwitch.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5)
mySwitch.addTarget(self, action: "switchChanged:", forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(mySwitch)

// turn the switch on
mySwitch.on = true

// Example of a bigger switch with images
let mySwitch2 = SevenSwitch(frame: CGRectMake(0, 0, 100, 50))
mySwitch2.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 - 80)
mySwitch2.addTarget(self, action: "switchChanged:", forControlEvents: UIControlEvents.ValueChanged)
mySwitch2.offImage = UIImage(named: "cross.png")
mySwitch2.onImage = UIImage(named: "check.png")
mySwitch2.onTintColor = UIColor(hue: 0.08, saturation: 0.74, brightness: 1.00, alpha: 1.00)
mySwitch2.isRounded = false
self.view.addSubview(mySwitch2)

// turn the switch on with animation
mySwitch2.setOn(true, animated: true)

// Example of color customization
let mySwitch3 = SevenSwitch(frame: CGRectZero)
mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70)
mySwitch3.addTarget(self, action: "switchChanged:", forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(mySwitch3)

//self.view.backgroundColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.thumbTintColor = UIColor(red: 0.19, green: 0.23, blue: 0.33, alpha: 1)
mySwitch3.activeColor = UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch3.inactiveColor = UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch3.onTintColor = UIColor(red: 0.45, green: 0.58, blue: 0.67, alpha: 1)
mySwitch3.borderColor = UIColor.clearColor()
mySwitch3.shadowColor = UIColor.blackColor()
}

func switchChanged(sender: SevenSwitch) {
println("Changed value to: \(sender.on)")
}
}

0 comments on commit 136c2d5

Please sign in to comment.