Skip to content

Commit

Permalink
Swift 4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
atecle committed Dec 26, 2017
1 parent 11fd7c9 commit 14e897d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 37 deletions.
29 changes: 23 additions & 6 deletions ATCircularProgressView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,19 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Adam Tecle";
TargetAttributes = {
668866071DC2901400545F43 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 3GR96D7Z4R;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
ProvisioningStyle = Automatic;
};
668866101DC2901400545F43 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 3GR96D7Z4R;
LastSwiftMigration = 0920;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -234,15 +235,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand Down Expand Up @@ -288,15 +295,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand Down Expand Up @@ -345,7 +358,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -367,7 +381,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.adamtecle.ATCircularProgressView;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -380,7 +395,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.adamtecle.ATCircularProgressViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -393,7 +409,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.adamtecle.ATCircularProgressViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
32 changes: 18 additions & 14 deletions ATCircularProgressView/CircularProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import UIKit
override init(frame: CGRect) {
super.init(frame: frame)
setup()

}

public required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -168,8 +167,7 @@ import UIKit
}

@objc private func displayLinkDidFire(_: CADisplayLink) {
guard let value = progressLayer.presentation()?.strokeEnd
else { return }
guard let value = progressLayer.presentation()?.strokeEnd else { return }

progressChanged?(self, value)
if value == destinationValue {
Expand All @@ -182,16 +180,22 @@ import UIKit
private func borderStrokePath(bounds: CGRect) -> CGPath {
let center = CGPoint(x: bounds.midX, y: bounds.midY)
let radius = bounds.midX

let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
let path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
return path.cgPath
}

private func progressStrokePath(bounds: CGRect) -> CGPath {
let center = CGPoint(x: bounds.midX, y: bounds.midY)
let radius = bounds.midX

let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
let path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: startAngle,
endAngle: endAngle,
clockwise: true)
return path.cgPath
}

Expand All @@ -205,8 +209,8 @@ import UIKit
}

private func createDisplayLink() {
guard displayLink == nil
else { return }
guard displayLink == nil else { return }

displayLink = CADisplayLink(target: self, selector: #selector(displayLinkDidFire(_:)))
displayLink?.isPaused = false
displayLink?.add(to: .main, forMode: .commonModes)
Expand All @@ -223,14 +227,14 @@ import UIKit
layer.addSublayer(borderLayer)
layer.addSublayer(progressLayer)

startAngle = CGFloat(-(M_PI * 0.5))
endAngle = CGFloat(3.0/4.0 * (M_PI * 2.0))
startAngle = CGFloat(-(Double.pi * 0.5))
endAngle = CGFloat(3.0/4.0 * (Double.pi * 2.0))
configureImageView()
}

private func configureCentralView() {
guard let centralView = centralView
else { return }
guard let centralView = centralView else { return }

centralView.translatesAutoresizingMaskIntoConstraints = false
addSubview(centralView)

Expand All @@ -255,7 +259,7 @@ import UIKit
let bottom = NSLayoutConstraint(item: imageView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1, constant: 0)
let width = NSLayoutConstraint(item: imageView, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 1, constant: 0)
let height = NSLayoutConstraint(item: imageView, attribute: .height, relatedBy: .equal, toItem: imageView, attribute: .width, multiplier: 1, constant: 0)
height.priority = UILayoutPriorityDefaultLow
height.priority = .defaultLow

addConstraints([top, leading, trailing, bottom, width, height])
}
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#ATCircularProgressView
# ATCircularProgressView
<p align="center">
<img height="420" src="assets/screenshot.gif"/>
</p>
Expand All @@ -10,23 +10,23 @@

A super simple circular progress view for iOS that you can customize in Storyboard, or in code. It's lightweight and performant - uses CAShapeLayers to do drawing and CADisplayLink to update you on the progress.

##Usage
## Usage

You can create an instance in code, or by dragging a UIView into your Storyboard and setting the subclass and module.

Here's how you set the progress
####Swift
#### Swift
```swift
progressView.setProgress(value: 0.5, animated: true, duration: 1, completion: nil)
```
####Objective-C
#### Objective-C
```objective-c
[self.progressView setProgressWithValue:0.5 animated:YES duration:1 completion:nil];
```
If you want to perform some work while the progress is changing, like update a label, set the `progressChanged` property
####Swift
#### Swift
```swift
let progressChanged: (CircularProgressView, CGFloat) -> () = { [unowned self]
(progressView, progress) in
Expand All @@ -37,7 +37,7 @@ If you want to perform some work while the progress is changing, like update a l
progressView.progressChanged = progressChanged
```

####Objective-C
#### Objective-C
```objective-c
__weak typeof(self) weakSelf = self;
self.progressView.progressChanged = ^(CircularProgressView *progressView, CGFloat progress) {
Expand All @@ -53,29 +53,29 @@ progressView.progressChanged = progressChanged
</p>
Check out the demo project and play around with it.
#Lame install
### Lame install
Just drag and drop CircularProgressView into your project
#Setup with CocoaPods
### Setup with CocoaPods
```
pod 'ATCircularProgressView'

use_frameworks!
```
#Setup with Carthage
### Setup with Carthage
```
git "atecle/ATCircularProgressView"
```
#Author
### Author
[@admtcl](https://twitter.com/admtcl)
#MIT License
# MIT License
The MIT License (MIT)
Copyright (c) 2016 Adam Tecle
Expand Down

0 comments on commit 14e897d

Please sign in to comment.