10 Commits

Author SHA1 Message Date
Alex.k d732302363 update podspec 2016-03-14 09:29:05 +03:00
Alex dc86cd2b03 Merge pull request #11 from joeblau/master
Make class public so it's accessable programmatically without Storyboards
2016-03-14 09:26:02 +03:00
Joe Blau 7b1159d718 Added color support on initialization 2016-03-13 13:49:20 -04:00
Joe Blau 3fcee77c2e Added view based initialization 2016-03-13 13:22:53 -04:00
Joe Blau 5b3d07a65f Make class public so it's accessable programmatically without Storyboards 2016-03-13 12:05:06 -04:00
Juri Vasylenko ef935a478c fixed typo in header.png name 2016-02-15 11:37:47 +03:00
Juri Vasylenko 865d501bca add header 2016-02-15 11:36:14 +03:00
Juri Vasylenko c866fb10f3 Update README.md 2016-02-01 12:14:12 +03:00
Juri Vasylenko 839fb5e072 Update README.md 2016-02-01 12:13:51 +03:00
Juri Vasylenko f3d5182872 Merge pull request #9 from Ramotion/docs_update
Docs update
2016-02-01 10:06:24 +03:00
4 changed files with 48 additions and 28 deletions
+43 -24
View File
@@ -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 -1
View File
@@ -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'
+4 -3
View File
@@ -1,3 +1,4 @@
![header](./header.png)
#RAMPaperSwitch
[![CocoaPods](https://img.shields.io/cocoapods/p/RAMPaperSwitch.svg)](https://cocoapods.org/pods/RAMPaperSwitch)
[![CocoaPods](https://img.shields.io/cocoapods/v/RAMPaperSwitch.svg)](http://cocoapods.org/pods/RAMPaperSwitch)
@@ -5,7 +6,7 @@
[![Twitter](https://img.shields.io/badge/Twitter-@Ramotion-blue.svg?style=flat)](http://twitter.com/Ramotion)
[![Travis](https://img.shields.io/travis/Ramotion/paper-switch.svg)](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.
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=https://github.com/ramotion/paper-switch)
[![Twitter Follow](https://img.shields.io/twitter/follow/ramotion.svg?style=social)](https://twitter.com/ramotion)
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB