Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBInspectable properties are added for on/off Text, on/off Text Color… #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 74 additions & 2 deletions SevenSwitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,91 @@ import QuartzCore
* Sets the text that shows when the switch is on.
* The text is centered in the area not covered by the knob.
*/
public var onLabel: UILabel!
@IBInspectable public var onText: String! {
willSet {
onLabel.text = newValue
}
}

/*
* Sets the text color of onLabel. Defaults to black.
*/
@IBInspectable public var onTextColor: UIColor = UIColor.blackColor() {
willSet {
onLabel.textColor = newValue
}
}

/*
* Sets the text size of onLabel. Defaults to UIFont.labelFontSize
*/
@IBInspectable public var onTextSize: CGFloat = UIFont.labelFontSize() {
willSet {
onLabel.font = UIFont(name: onLabel.font.fontName, size: newValue)
}
}

/*
* Set whether the text style is bold(on) or not(off). Defaults to not bold
*/
@IBInspectable public var onTextIsBold: Bool = false {
willSet(isBold) {
if isBold {
onLabel.font = UIFont.boldSystemFontOfSize(onLabel.font.pointSize)
} else {
onLabel.font = UIFont(name: onLabel.font.fontName, size: onLabel.font.pointSize)
}
}
}

/*
* Sets the text that shows when the switch is off.
* The text is centered in the area not covered by the knob.
*/
public var offLabel: UILabel!
@IBInspectable public var offText: String! {
willSet {
offLabel.text = newValue
}
}

/*
* Sets the text color of offLabel. Defaults to black.
*/
@IBInspectable public var offTextColor: UIColor = UIColor.blackColor() {
willSet {
offLabel.textColor = newValue
}
}

/*
* Sets the text size of offLabel. Defaults to UIFont.labelFontSize
*/
@IBInspectable public var offTextSize: CGFloat = UIFont.labelFontSize() {
willSet {
offLabel.font = UIFont(name: offLabel.font.fontName, size: newValue)
}
}

/*
* Set whether the text style is bold(on) or not(off). Defaults to not bold
*/
@IBInspectable public var offTextIsBold: Bool = false {
willSet(isBold) {
if isBold {
offLabel.font = UIFont.boldSystemFontOfSize(offLabel.font.pointSize)
} else {
offLabel.font = UIFont(name: offLabel.font.fontName, size: offLabel.font.pointSize)
}
}
}

// internal
internal var backgroundView: UIView!
internal var thumbView: UIView!
internal var onImageView: UIImageView!
internal var onLabel: UILabel!
internal var offImageView: UIImageView!
internal var offLabel: UILabel!
internal var thumbImageView: UIImageView!
// private
private var currentVisualValue: Bool = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="2">
<dependencies>
<deployment identifier="iOS"/>
<development version="6000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -19,18 +19,59 @@
<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"/>
<rect key="frame" x="118" y="113" width="85" height="46"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="85" id="2m5-2R-1DF"/>
<constraint firstAttribute="height" constant="46" id="hlw-Ds-Cgk"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="on" value="YES"/>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="A6g-wm-eTB" customClass="SevenSwitch" customModule="SevenSwitchExample" customModuleProvider="target">
<rect key="frame" x="103" y="37" width="115" height="46"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="46" id="6f2-Td-gBQ"/>
<constraint firstAttribute="width" constant="115" id="Reb-eB-FM9"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="on" value="NO"/>
<userDefinedRuntimeAttribute type="string" keyPath="onText" value="On"/>
<userDefinedRuntimeAttribute type="string" keyPath="offText" value="Off"/>
<userDefinedRuntimeAttribute type="color" keyPath="onTextColor">
<color key="value" white="1" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="offTextColor">
<color key="value" white="1" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="onTextSize">
<real key="value" value="32"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="offTextSize">
<real key="value" value="32"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="onTextIsBold" value="YES"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="offTextIsBold" value="YES"/>
<userDefinedRuntimeAttribute type="color" keyPath="borderColor">
<color key="value" red="0.92941176469999998" green="0.35686274509999999" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="inactiveColor">
<color key="value" red="0.92941176469999998" green="0.35686274509999999" blue="0.15686274510000001" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<animations/>
<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="top" secondItem="A6g-wm-eTB" secondAttribute="bottom" constant="30" id="PHb-ft-kyA"/>
<constraint firstItem="A6g-wm-eTB" firstAttribute="top" secondItem="2j3-pC-O9b" secondAttribute="bottom" constant="17" id="YLV-Tv-akp"/>
<constraint firstItem="htP-wM-0uv" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" id="oRk-du-DXW"/>
<constraint firstItem="A6g-wm-eTB" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" id="oVi-NZ-XPY"/>
</constraints>
</view>
<connections>
Expand All @@ -39,11 +80,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="305" y="357"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>