Skip to content

Commit

Permalink
Merge pull request #29 from MoathOthman/master
Browse files Browse the repository at this point in the history
Adding @IBDesignable and  @IBInspectable properties
  • Loading branch information
bvogelzang committed Mar 3, 2015
2 parents 34504a2 + 7e03e43 commit 0eb46e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
26 changes: 13 additions & 13 deletions SevenSwitch.swift
Expand Up @@ -25,14 +25,14 @@
import UIKit
import QuartzCore

@objc class SevenSwitch: UIControl {
@IBDesignable @objc class SevenSwitch: UIControl {

// public

/*
* Set (without animation) whether the switch is on or off
*/
var on: Bool {
@IBInspectable var on: Bool {
get {
return switchValue
}
Expand All @@ -46,7 +46,7 @@ import QuartzCore
* Sets the background color that shows when the switch off and actively being touched.
* Defaults to light gray.
*/
var activeColor: UIColor = UIColor(red: 0.89, green: 0.89, blue: 0.89, alpha: 1) {
@IBInspectable var activeColor: UIColor = UIColor(red: 0.89, green: 0.89, blue: 0.89, alpha: 1) {
willSet {
if self.on && !self.tracking {
backgroundView.backgroundColor = newValue
Expand All @@ -58,7 +58,7 @@ import QuartzCore
* Sets the background color when the switch is off.
* Defaults to clear color.
*/
var inactiveColor: UIColor = UIColor.clearColor() {
@IBInspectable var inactiveColor: UIColor = UIColor.clearColor() {
willSet {
if !self.on && !self.tracking {
backgroundView.backgroundColor = newValue
Expand All @@ -70,7 +70,7 @@ import QuartzCore
* Sets the background color that shows when the switch is on.
* Defaults to green.
*/
var onTintColor: UIColor = UIColor(red: 0.3, green: 0.85, blue: 0.39, alpha: 1) {
@IBInspectable var onTintColor: UIColor = UIColor(red: 0.3, green: 0.85, blue: 0.39, alpha: 1) {
willSet {
if self.on && !self.tracking {
backgroundView.backgroundColor = newValue
Expand All @@ -84,7 +84,7 @@ import QuartzCore
/*
* Sets the border color that shows when the switch is off. Defaults to light gray.
*/
var borderColor: UIColor = UIColor(red: 0.78, green: 0.78, blue: 0.8, alpha: 1) {
@IBInspectable var borderColor: UIColor = UIColor(red: 0.78, green: 0.78, blue: 0.8, alpha: 1) {
willSet {
if !self.on {
backgroundView.layer.borderColor = newValue.CGColor
Expand All @@ -95,7 +95,7 @@ import QuartzCore
/*
* Sets the knob color. Defaults to white.
*/
var thumbTintColor: UIColor = UIColor.whiteColor() {
@IBInspectable var thumbTintColor: UIColor = UIColor.whiteColor() {
willSet {
if !userDidSpecifyOnThumbTintColor {
onThumbTintColor = newValue
Expand All @@ -109,7 +109,7 @@ import QuartzCore
/*
* Sets the knob color that shows when the switch is on. Defaults to white.
*/
var onThumbTintColor: UIColor = UIColor.whiteColor() {
@IBInspectable var onThumbTintColor: UIColor = UIColor.whiteColor() {
willSet {
userDidSpecifyOnThumbTintColor = true
if self.on && !self.tracking {
Expand All @@ -121,7 +121,7 @@ import QuartzCore
/*
* Sets the shadow color of the knob. Defaults to gray.
*/
var shadowColor: UIColor = UIColor.grayColor() {
@IBInspectable var shadowColor: UIColor = UIColor.grayColor() {
willSet {
thumbView.layer.shadowColor = newValue.CGColor
}
Expand All @@ -132,7 +132,7 @@ import QuartzCore
* Set to NO to get a stylish square switch.
* Defaults to YES.
*/
var isRounded: Bool = true {
@IBInspectable var isRounded: Bool = true {
willSet {
if newValue {
backgroundView.layer.cornerRadius = self.frame.size.height * 0.5
Expand All @@ -150,7 +150,7 @@ import QuartzCore
/*
* Sets the image that shows on the switch thumb.
*/
var thumbImage: UIImage! {
@IBInspectable var thumbImage: UIImage! {
willSet {
thumbImageView.image = newValue
}
Expand All @@ -161,7 +161,7 @@ import QuartzCore
* The image is centered in the area not covered by the knob.
* Make sure to size your images appropriately.
*/
var onImage: UIImage! {
@IBInspectable var onImage: UIImage! {
willSet {
onImageView.image = newValue
}
Expand All @@ -172,7 +172,7 @@ import QuartzCore
* The image is centered in the area not covered by the knob.
* Make sure to size your images appropriately.
*/
var offImage: UIImage! {
@IBInspectable var offImage: UIImage! {
willSet {
offImageView.image = newValue
}
Expand Down
@@ -1,32 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none" useAutolayout="YES" promptedForUpgradeToXcode5="NO" initialViewController="2">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" promptedForUpgradeToXcode5="NO" initialViewController="2">
<dependencies>
<deployment defaultVersion="1552" identifier="iOS"/>
<development version="4600" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
<deployment identifier="iOS"/>
<development version="6000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="ViewController" customModule="SevenSwitchExample" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="2j3-pC-O9b"/>
<viewControllerLayoutGuide type="bottom" id="mue-7X-CgM"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="548"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="htP-wM-0uv" customClass="SevenSwitch" customModule="SevenSwitchExample">
<rect key="frame" x="117" y="85" width="85" height="46"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="85" type="user" id="2m5-2R-1DF"/>
<constraint firstAttribute="height" constant="46" type="user" id="hlw-Ds-Cgk"/>
<constraint firstAttribute="width" constant="85" id="2m5-2R-1DF"/>
<constraint firstAttribute="height" constant="46" id="hlw-Ds-Cgk"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="htP-wM-0uv" firstAttribute="top" secondItem="3" secondAttribute="top" constant="85" id="CAm-AU-494"/>
<constraint firstItem="htP-wM-0uv" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" type="user" id="oRk-du-DXW"/>
<constraint firstItem="htP-wM-0uv" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" id="oRk-du-DXW"/>
</constraints>
</view>
<connections>
Expand Down

0 comments on commit 0eb46e6

Please sign in to comment.