Compare commits
10 Commits
docs_update
..
0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| d732302363 | |||
| dc86cd2b03 | |||
| 7b1159d718 | |||
| 3fcee77c2e | |||
| 5b3d07a65f | |||
| ef935a478c | |||
| 865d501bca | |||
| c866fb10f3 | |||
| 839fb5e072 | |||
| f3d5182872 |
@@ -22,7 +22,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
class RAMPaperSwitch: UISwitch {
|
||||
public class RAMPaperSwitch: UISwitch {
|
||||
|
||||
@IBInspectable var duration: Double = 0.35
|
||||
|
||||
@@ -33,13 +33,13 @@ class RAMPaperSwitch: UISwitch {
|
||||
private var radius: CGFloat = 0.0
|
||||
private var oldState = false
|
||||
|
||||
override var on: Bool {
|
||||
override public var on: Bool {
|
||||
didSet(oldValue) {
|
||||
oldState = on
|
||||
}
|
||||
}
|
||||
|
||||
override func setOn(on: Bool, animated: Bool) {
|
||||
override public func setOn(on: Bool, animated: Bool) {
|
||||
let changed:Bool = on != self.on
|
||||
|
||||
super.setOn(on, animated: animated)
|
||||
@@ -54,18 +54,28 @@ class RAMPaperSwitch: UISwitch {
|
||||
}
|
||||
|
||||
|
||||
override func layoutSubviews() {
|
||||
let x:CGFloat = max(frame.midX, superview!.frame.size.width - frame.midX);
|
||||
let y:CGFloat = max(frame.midY, superview!.frame.size.height - frame.midY);
|
||||
radius = sqrt(x*x + y*y);
|
||||
|
||||
shape.frame = CGRectMake(frame.midX - radius, frame.midY - radius, radius * 2, radius * 2)
|
||||
shape.anchorPoint = CGPointMake(0.5, 0.5);
|
||||
shape.path = UIBezierPath(ovalInRect: CGRectMake(0, 0, radius * 2, radius * 2)).CGPath
|
||||
// MARK: - Initialization
|
||||
|
||||
|
||||
public required init(view: UIView?, color: UIColor?) {
|
||||
super.init(frame: CGRectZero)
|
||||
onTintColor = color
|
||||
self.commonInit(view)
|
||||
}
|
||||
|
||||
|
||||
override func awakeFromNib() {
|
||||
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
|
||||
override public func awakeFromNib() {
|
||||
self.commonInit(superview)
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
|
||||
private func commonInit(parentView: UIView?) {
|
||||
let shapeColor: UIColor = onTintColor ?? UIColor.greenColor()
|
||||
|
||||
layer.borderWidth = 0.5
|
||||
@@ -75,22 +85,32 @@ class RAMPaperSwitch: UISwitch {
|
||||
shape.fillColor = shapeColor.CGColor
|
||||
shape.masksToBounds = true
|
||||
|
||||
superview?.layer.insertSublayer(shape, atIndex: 0)
|
||||
superview?.layer.masksToBounds = true
|
||||
parentView?.layer.insertSublayer(shape, atIndex: 0)
|
||||
parentView?.layer.masksToBounds = true
|
||||
|
||||
showShapeIfNeed()
|
||||
|
||||
addTarget(self, action: "switchChanged", forControlEvents: UIControlEvents.ValueChanged)
|
||||
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
|
||||
override public func layoutSubviews() {
|
||||
let x:CGFloat = max(frame.midX, superview!.frame.size.width - frame.midX);
|
||||
let y:CGFloat = max(frame.midY, superview!.frame.size.height - frame.midY);
|
||||
radius = sqrt(x*x + y*y);
|
||||
|
||||
shape.frame = CGRectMake(frame.midX - radius, frame.midY - radius, radius * 2, radius * 2)
|
||||
shape.anchorPoint = CGPointMake(0.5, 0.5);
|
||||
shape.path = UIBezierPath(ovalInRect: CGRectMake(0, 0, radius * 2, radius * 2)).CGPath
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func showShapeIfNeed() {
|
||||
shape.transform = on ? CATransform3DMakeScale(1.0, 1.0, 1.0) : CATransform3DMakeScale(0.0001, 0.0001, 0.0001)
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal func switchChanged() {
|
||||
if on == oldState {
|
||||
return;
|
||||
@@ -143,16 +163,15 @@ class RAMPaperSwitch: UISwitch {
|
||||
return animation;
|
||||
}
|
||||
|
||||
//MARK: - CAAnimation Delegate
|
||||
|
||||
|
||||
//CAAnimation delegate
|
||||
|
||||
|
||||
override func animationDidStart(anim: CAAnimation){
|
||||
override public func animationDidStart(anim: CAAnimation){
|
||||
animationDidStartClosure(on)
|
||||
}
|
||||
|
||||
|
||||
override func animationDidStop(anim: CAAnimation, finished flag: Bool){
|
||||
override public func animationDidStop(anim: CAAnimation, finished flag: Bool){
|
||||
animationDidStopClosure(on, flag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'RAMPaperSwitch'
|
||||
s.version = '0.0.1'
|
||||
s.version = '0.0.2'
|
||||
s.summary = 'Swift subclass of the UISwitch which paints over the parent view'
|
||||
s.homepage = 'https://github.com/Ramotion/paper-switch'
|
||||
s.license = 'MIT'
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||

|
||||
#RAMPaperSwitch
|
||||
[](https://cocoapods.org/pods/RAMPaperSwitch)
|
||||
[](http://cocoapods.org/pods/RAMPaperSwitch)
|
||||
@@ -5,7 +6,7 @@
|
||||
[](http://twitter.com/Ramotion)
|
||||
[](https://travis-ci.org/Ramotion/paper-switch)
|
||||
|
||||
Swift subclass of the UISwitch which paints over the parent view with the `onTintColor` when the switch is turned on. Implemented concept from [this Dribbble](https://dribbble.com/shots/1749645-Contact-Sync) shot by [Ramotion](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch).
|
||||
Swift subclass of the UISwitch which paints over the parent view with the `onTintColor` when the switch is turned on. Implemented concept from [this Dribbble](https://dribbble.com/shots/1749645-Contact-Sync) shot by [Ramotion](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch).
|
||||
|
||||
|
||||
#Screenshot
|
||||
@@ -57,8 +58,8 @@ self.paperSwitch.animationDidStartClosure = {(onAnimation: Bool) in
|
||||
```
|
||||
|
||||
## About
|
||||
The project maintained by [app development agency](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch) [Ramotion Inc.](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch)
|
||||
See our other [open-source projects](https://github.com/ramotion) or [hire](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch) us to design, develop, and grow your product.
|
||||
The project maintained by [app development agency](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch) [Ramotion Inc.](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch)
|
||||
See our other [open-source projects](https://github.com/ramotion) or [hire](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch) us to design, develop, and grow your product.
|
||||
|
||||
[](https://twitter.com/intent/tweet?text=https://github.com/ramotion/paper-switch)
|
||||
[](https://twitter.com/ramotion)
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user