Skip to content

Commit

Permalink
Merge pull request #62 from rob-nash/master
Browse files Browse the repository at this point in the history
Added demo playground
Fixed rendering bug.
  • Loading branch information
Marxon13 authored Sep 28, 2016
2 parents 7cd14c1 + 77bc590 commit 0294410
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ M13Checkbox.xcodeproj/xcuserdata/
M13Checkbox.xcworkspace/
Pods/
Podfile.lock
Playground/LaunchMe.xcworkspace/xcuserdata/*
10 changes: 10 additions & 0 deletions Playground/LaunchMe.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Playground/Playground.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//: Playground - noun: a place where people can play

import M13Checkbox
import PlaygroundSupport

let checkbox = M13Checkbox(frame: CGRect(x: 0.0, y: 0.0, width: 250.0, height: 250.0))
checkbox.backgroundColor = .white
checkbox.tintColor = .yellow
checkbox.secondaryTintColor = .green
checkbox.secondaryCheckmarkTintColor = .red
checkbox.checkmarkLineWidth = 2.0
checkbox.stateChangeAnimation = .bounce(.fill)

PlaygroundPage.current.liveView = checkbox
4 changes: 4 additions & 0 deletions Playground/Playground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Check out the demo app to change the properties of the checkbox and see the chan

##Getting Started

###Demo

To see a working playground in action, run the workspace located at path Playground/LaunchMe.xcworkspace. You may need to run the framework scheme and wait for Xcode to process the files, before the playground begins. Open the assistant editor for a live preview of the UI.

### Installation

#### Cocoapods
Expand Down
12 changes: 6 additions & 6 deletions Sources/M13CheckboxPathPresets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ internal class M13CheckboxPathPresets {
let d = size * cos(theta) * (cos(theta) - sin(theta))
let e = 2.0 * cornerRadius * sin(theta) * (cos(theta) + sin(theta))

let x = 0.25 * (a + (2.0 * (b + sqrt(c)) * cos(theta)))
let y = 0.50 * (d + e - (sqrt(c) * sin(theta)))
let x = 0.25 * (a + (2.0 * (b + sqrt(c)) * cos(theta))) + (boxLineWidth / 2.0)
let y = 0.50 * (d + e - (sqrt(c) * sin(theta))) + (boxLineWidth / 2.0)

return CGPoint(x: x, y: y)
}
Expand Down Expand Up @@ -141,22 +141,22 @@ internal class M13CheckboxPathPresets {
let subX1 = (b * cd) + pow(e1 + e2, 2.0)
let subY1 = pow(h1 + h2, 2.0) + (b * (d1 + i + j))

let x = (0.5 * (a1 + a2 + (0.5 * sqrt(subX1)))) / f
let y = (g1 + g2 - (0.25 * sqrt(subY1))) / f
let x = (0.5 * (a1 + a2 + (0.5 * sqrt(subX1))) + (boxLineWidth / 2.0)) / f
let y = (g1 + g2 - (0.25 * sqrt(subY1)) + (boxLineWidth / 2.0)) / f

return CGPoint(x: x, y: y)
}

var checkmarkMiddlePoint: CGPoint {
let r = boxType == .circle ? checkmarkProperties.middlePointRadius.circle : checkmarkProperties.middlePointRadius.box
let o = boxType == .circle ? checkmarkProperties.middlePointOffset.circle : checkmarkProperties.middlePointOffset.box
return CGPoint(x: (size / 2.0) + (size * o), y: (size / 2.0 ) + (size * r))
return CGPoint(x: (size / 2.0) + (size * o) + (boxLineWidth / 2.0), y: (size / 2.0 ) + (size * r) + (boxLineWidth / 2.0))
}

var checkmarkShortArmEndPoint: CGPoint {
let r = boxType == .circle ? checkmarkProperties.shortArmRadius.circle : checkmarkProperties.shortArmRadius.box
let o = boxType == .circle ? checkmarkProperties.shortArmOffset.circle : checkmarkProperties.shortArmOffset.box
return CGPoint(x: (size / 2.0) - (size * r), y: (size / 2.0) + (size * o))
return CGPoint(x: (size / 2.0) - (size * r) + (boxLineWidth / 2.0), y: (size / 2.0) + (size * o) + (boxLineWidth / 2.0))
}

//----------------------------
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxBounceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ internal class M13CheckboxBounceManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxDotManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ internal class M13CheckboxDotManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = (paths as! M13CheckboxDotPathPresets).pathForDot().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxExpandManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ internal class M13CheckboxExpandManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxFadeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ internal class M13CheckboxFadeManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxFillManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ internal class M13CheckboxFillManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxFlatManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ internal class M13CheckboxFlatManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxSpiralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ internal class M13CheckboxSpiralManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down
8 changes: 5 additions & 3 deletions Sources/Managers/M13CheckboxStrokeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ internal class M13CheckboxStrokeManager: M13CheckboxManager {

override func layoutLayers() {
// Frames
unselectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: 0.0, y: 0.0, width: paths.size, height: paths.size)
let x: CGFloat = paths.boxLineWidth / 2.0
let y: CGFloat = paths.boxLineWidth / 2.0
unselectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
selectedBoxLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
markLayer.frame = CGRect(x: x, y: y, width: paths.size, height: paths.size)
// Paths
unselectedBoxLayer.path = paths.pathForBox().cgPath
selectedBoxLayer.path = paths.pathForBox().cgPath
Expand Down

0 comments on commit 0294410

Please sign in to comment.