11 Commits

Author SHA1 Message Date
Kaan Dedeoglu 466be89f6d Merge pull request #10 from kaandedeoglu/swift2.0
Swift2.0
2015-09-16 20:30:09 +03:00
Kaan Dedeoglu b9f8a3e46e Update README.md 2015-09-15 19:26:58 +03:00
Kaan Dedeoglu b9cdde76e5 Reorganize some properties, add description about progressInsideFillColor 2015-09-11 11:09:44 +03:00
Kaan Dedeoglu f7959fdd54 Add note about IBInspectable and IBDesignable support 2015-09-10 23:10:43 +03:00
Kaan Dedeoglu c01c9d9b59 Add progressInsideFillColor IBInspectable property 2015-09-10 23:06:37 +03:00
Kaan Dedeoglu 125bfcc5a4 Beta 7 fixes 2015-08-25 02:47:15 +03:00
Kaan Dedeoglu e823e29b2e Merge branch 'master' of https://github.com/kaandedeoglu/KDCircularProgress into swift2.0 2015-08-17 20:01:54 +03:00
Kaan Dedeoglu ee6a46abd3 Make IBOutletColor1-2-3 properties private. 2015-07-01 12:28:50 +03:00
Kaan Dedeoglu a90c94254e Swift 2.0 changes 2015-06-28 11:43:44 +03:00
Kaan Dedeoglu 9fb2796b70 Update README.md 2015-06-25 17:38:31 +03:00
Kaan Dedeoglu 58cbb4a4a6 Update Podspec, push 1.1 to pods 2015-06-25 17:35:14 +03:00
6 changed files with 59 additions and 37 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'KDCircularProgress'
s.version = '1.0'
s.version = '1.1'
s.license = 'MIT'
s.summary = 'A circular progress view with gradients written in Swift'
s.homepage = 'https://github.com/kaandedeoglu/KDCircularProgress'
+33 -21
View File
@@ -130,6 +130,16 @@ public class KDCircularProgress: UIView {
}
}
@IBInspectable public var progressInsideFillColor: UIColor? = nil {
didSet {
if let color = progressInsideFillColor {
progressLayer.progressInsideFillColor = color
} else {
progressLayer.progressInsideFillColor = UIColor.clearColor()
}
}
}
@IBInspectable public var progressColors: [UIColor]! {
get {
return progressLayer.colorsArray
@@ -142,9 +152,9 @@ public class KDCircularProgress: UIView {
//These are used only from the Interface-Builder. Changing these from code will have no effect.
//Also IB colors are limited to 3, whereas programatically we can have an arbitrary number of them.
@IBInspectable public var IBColor1: UIColor?
@IBInspectable public var IBColor2: UIColor?
@IBInspectable public var IBColor3: UIColor?
@objc @IBInspectable private var IBColor1: UIColor?
@objc @IBInspectable private var IBColor2: UIColor?
@objc @IBInspectable private var IBColor3: UIColor?
private var animationCompletionBlock: ((Bool) -> Void)?
@@ -163,8 +173,8 @@ public class KDCircularProgress: UIView {
}
required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setTranslatesAutoresizingMaskIntoConstraints(false)
super.init(coder: aDecoder)!
translatesAutoresizingMaskIntoConstraints = false
userInteractionEnabled = false
setInitialValues()
refreshValues()
@@ -245,7 +255,6 @@ public class KDCircularProgress: UIView {
}
public func stopAnimation() {
let presentationLayer = progressLayer.presentationLayer() as! KDCircularProgressViewLayer
progressLayer.removeAllAnimations()
angle = 0
}
@@ -254,7 +263,7 @@ public class KDCircularProgress: UIView {
return progressLayer.animationForKey("angle") != nil
}
override public func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
override public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let completionBlock = animationCompletionBlock {
completionBlock(flag)
animationCompletionBlock = nil
@@ -292,6 +301,7 @@ public class KDCircularProgress: UIView {
var progressThickness: CGFloat!
var trackThickness: CGFloat!
var trackColor: UIColor!
var progressInsideFillColor: UIColor = UIColor.clearColor()
var colorsArray: [UIColor]! {
didSet {
gradientCache = nil
@@ -317,11 +327,11 @@ public class KDCircularProgress: UIView {
}
}
override class func needsDisplayForKey(key: String!) -> Bool {
override class func needsDisplayForKey(key: String) -> Bool {
return key == "angle" ? true : super.needsDisplayForKey(key)
}
override init!(layer: AnyObject!) {
override init(layer: AnyObject) {
super.init(layer: layer)
let progressLayer = layer as! KDCircularProgressViewLayer
radius = progressLayer.radius
@@ -338,15 +348,15 @@ public class KDCircularProgress: UIView {
colorsArray = progressLayer.colorsArray
}
override init!() {
override init() {
super.init()
}
required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawInContext(ctx: CGContext!) {
override func drawInContext(ctx: CGContext) {
UIGraphicsPushContext(ctx)
let rect = bounds
let size = rect.size
@@ -356,9 +366,11 @@ public class KDCircularProgress: UIView {
let arcRadius = max(radius - trackLineWidth/2, radius - progressLineWidth/2)
CGContextAddArc(ctx, CGFloat(size.width/2.0), CGFloat(size.height/2.0), arcRadius, 0, CGFloat(M_PI * 2), 0)
trackColor.set()
CGContextSetStrokeColorWithColor(ctx, trackColor.CGColor)
CGContextSetFillColorWithColor(ctx, progressInsideFillColor.CGColor)
CGContextSetLineWidth(ctx, trackLineWidth)
CGContextSetLineCap(ctx, kCGLineCapButt)
CGContextDrawPath(ctx, kCGPathStroke)
CGContextSetLineCap(ctx, CGLineCap.Butt)
CGContextDrawPath(ctx, .FillStroke)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
let imageCtx = UIGraphicsGetCurrentContext()
@@ -370,11 +382,11 @@ public class KDCircularProgress: UIView {
if glowValue > 0 {
CGContextSetShadowWithColor(imageCtx, CGSizeZero, glowValue, UIColor.blackColor().CGColor)
}
CGContextSetLineCap(imageCtx, roundedCorners == true ? kCGLineCapRound : kCGLineCapButt)
CGContextSetLineCap(imageCtx, roundedCorners == true ? .Round : .Butt)
CGContextSetLineWidth(imageCtx, progressLineWidth)
CGContextDrawPath(imageCtx, kCGPathStroke)
CGContextDrawPath(imageCtx, .Stroke)
let drawMask: CGImageRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext())
let drawMask: CGImageRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext())!
UIGraphicsEndImageContext()
CGContextSaveGState(ctx)
@@ -394,7 +406,7 @@ public class KDCircularProgress: UIView {
for color in rgbColorsArray {
let colorComponents: UnsafePointer<CGFloat> = CGColorGetComponents(color.CGColor)
componentsArray.extend([colorComponents[0],colorComponents[1],colorComponents[2],1.0])
componentsArray.appendContentsOf([colorComponents[0],colorComponents[1],colorComponents[2],1.0])
}
drawGradientWithContext(ctx, componentsArray: componentsArray)
@@ -424,19 +436,19 @@ public class KDCircularProgress: UIView {
} else {
let g = CGGradientCreateWithColorComponents(baseSpace, componentsArray, locations,componentsArray.count / 4)
self.gradientCache = g
gradient = g
gradient = g!
}
let halfX = bounds.size.width/2.0
let floatPi = CGFloat(M_PI)
let rotateSpeed = clockwise == true ? gradientRotateSpeed : gradientRotateSpeed * -1
let angleInRadians = ConversionFunctions.DegreesToRadians(rotateSpeed * CGFloat(angle) - 90)
var oppositeAngle = angleInRadians > floatPi ? angleInRadians - floatPi : angleInRadians + floatPi
let oppositeAngle = angleInRadians > floatPi ? angleInRadians - floatPi : angleInRadians + floatPi
let startPoint = CGPoint(x: (cos(angleInRadians) * halfX) + halfX, y: (sin(angleInRadians) * halfX) + halfX)
let endPoint = CGPoint(x: (cos(oppositeAngle) * halfX) + halfX, y: (sin(oppositeAngle) * halfX) + halfX)
CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, 0)
CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, .DrawsBeforeStartLocation)
}
func gradientLocationsFromColorCount(colorCount: Int, gradientWidth: CGFloat) -> [CGFloat] {
@@ -168,6 +168,7 @@
BC9E757E1A8CE4A500B1DF3D /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Kaan Dedeoglu";
TargetAttributes = {
@@ -418,6 +419,7 @@
BC9E75A71A8CE4A500B1DF3D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
BC9E75A81A8CE4A500B1DF3D /* Build configuration list for PBXNativeTarget "KDCircularProgressExampleTests" */ = {
isa = XCConfigurationList;
@@ -426,6 +428,7 @@
BC9E75AA1A8CE4A500B1DF3D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A279b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<scenes>
@@ -19,6 +20,7 @@
<subviews>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="360" translatesAutoresizingMaskIntoConstraints="NO" id="BHN-x6-Zsx">
<rect key="frame" x="61" y="478" width="198" height="31"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="6DH-hv-h4S"/>
<constraint firstAttribute="width" constant="194" id="oTI-kD-sOa"/>
@@ -29,6 +31,7 @@
</slider>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5M2-Yi-RuL">
<rect key="frame" x="112" y="523" width="96" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="96" id="T9z-qf-POZ"/>
<constraint firstAttribute="height" constant="30" id="h5a-bV-EMl"/>
@@ -42,6 +45,7 @@
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wev-Tz-pfW" customClass="KDCircularProgress" customModule="KDCircularProgressExample" customModuleProvider="target">
<rect key="frame" x="60" y="20" width="200" height="200"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="191-H5-EIc"/>
@@ -80,6 +84,7 @@
</userDefinedRuntimeAttributes>
</view>
</subviews>
<animations/>
<color key="backgroundColor" red="0.4736600907821229" green="0.4736600907821229" blue="0.4736600907821229" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="BHN-x6-Zsx" secondAttribute="centerX" id="Arq-5P-YRp"/>
@@ -96,9 +101,4 @@
<point key="canvasLocation" x="410" y="396"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
@@ -37,9 +37,9 @@ class ViewController: UIViewController {
@IBAction func animateButtonTapped(sender: UIButton) {
progress.animateToAngle(360, duration: 5) { completed in
if completed {
println("animation stopped, completed")
print("animation stopped, completed")
} else {
println("animation stopped, was interrupted")
print("animation stopped, was interrupted")
}
}
}
+13 -6
View File
@@ -1,5 +1,9 @@
# KDCircularProgress
`KDCircularProgress` is a circular progress view written in Swift. It makes it possible to have gradients in the progress view, along with glows and animations. Here's an example
`KDCircularProgress` is a circular progress view written in Swift. It makes it possible to have gradients in the progress view, along with glows and animations.
KDCircularProgress also has `IBInspectable` and `IBDesignable` support, so you can configure and preview inside the `Interface Builder`.
Here's an example
[Youtube Link](http://youtu.be/iIdas72MXOg)
@@ -34,6 +38,9 @@ view.addSubview(progress)
## Properties
####progressColors: `[UIColor]`
The colors used to generate the gradient of the progress. You can also set this using the variadic `setColors(UIColor...)` method. A gradient is used only if there is more than one color. A fill is used otherwise. The default is a white fill.
####angle: `Int`
The angle of the progress. Between 0 and 360 (inclusive). Simply change its value in order to change the visual progress of the component. Default is 0.
@@ -47,7 +54,7 @@ Clockwise if true, Counter-clockwise if false. Default is true.
When true, the ends of the progress track will be drawn with a half circle radius. Default is false.
####gradientRotateSpeed: `CGFloat`
Describes how many times the underlying gradient will turn for each full cycle of the progress. Integer values recommended. Default is 0.
Describes how many times the underlying gradient will perform a 2π rotation for each full cycle of the progress. Integer values recommended. Default is 0.
####glowAmount: `CGFloat`
The intensity of the glow. Between 0 and 1.0. Default is 1.0.
@@ -70,10 +77,10 @@ The thickness of the progress. Between 0 and 1. Default is 0.4
The thickness of the background track. Between 0 and 1. Default is 0.5
####trackColor: `UIColor`
The color of the background track. Default is black.
The color of the background track. Default is `UIColor.blackColor()`.
####progressColors: `[UIColor]`
The colors used to generate the gradient of the progress. You can also set this using the variadic setColors(UIColor...) method. A gradient is used only if there is more than one color. A fill is used otherwise. The default is a white fill.
####progressInsideFillColor: `UIColor`
The color of the center of the circle. Default is `UIColor.clearColor()`.
##Methods
```swift
@@ -123,7 +130,7 @@ Prefering light colors in the gradients gives better results. As mentioned befor
- [x] Add example project
- [ ] Carthage Support
- [x] Cocoapods Support
- [ ] IBDesignable/IBInspectable support
- [x] IBDesignable/IBInspectable support
- [ ] Adding a `progress` property as an alternative to `angle`
- [ ] Clean up