Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from gizmosachin/swift3
Browse files Browse the repository at this point in the history
Add Swift 3 compatibility
  • Loading branch information
gizmosachin authored Oct 1, 2016
2 parents e4dc6ea + 9d419f2 commit fa7a40e
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode7.2
osx_image: xcode8
env:
global:
- LC_CTYPE=en_US.UTF-8
Expand All @@ -9,5 +9,5 @@ before_install:
- brew reinstall xctool
script:
- xcodebuild -showsdks
- xctool -project ColorSlider/ColorSlider.xcodeproj -scheme ColorSlider -sdk iphonesimulator9.2 build analyze
- xcodebuild -project ColorSlider/ColorSlider.xcodeproj -scheme ColorSlider -sdk iphonesimulator10.0 build analyze

2 changes: 1 addition & 1 deletion ColorSlider.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ColorSlider'
s.version = '2.5.1'
s.version = '3.0'
s.summary = 'Snapchat-style color picker with live preview'
s.homepage = 'http://github.com/gizmosachin/ColorSlider'
s.license = 'MIT'
Expand Down
3 changes: 3 additions & 0 deletions ColorSlider/ColorSlider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
TargetAttributes = {
46E735C01C6338F900B63587 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -240,6 +241,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -257,6 +259,7 @@
PRODUCT_BUNDLE_IDENTIFIER = tfw.ColorSlider;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
3 changes: 3 additions & 0 deletions Example/Sketchpad.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
0375B1D51A638D9B00990FEB = {
CreatedOnToolsVersion = 6.2;
DevelopmentTeam = 9BZNV2TE99;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -337,6 +338,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.Sketchpad.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = Sketchpad/BridgingHeader.h;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -353,6 +355,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.Sketchpad.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = Sketchpad/BridgingHeader.h;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
20 changes: 10 additions & 10 deletions Example/Sketchpad/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.backgroundColor = .whiteColor()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()

return true
}
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
Expand Down
52 changes: 26 additions & 26 deletions Example/Sketchpad/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ViewController: UIViewController, ACEDrawingViewDelegate {
let selectedColorView: UIView
let selectedColorItem: UIBarButtonItem

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
drawingView = ACEDrawingView()
colorSlider = ColorSlider()

Expand All @@ -62,19 +62,19 @@ class ViewController: UIViewController, ACEDrawingViewDelegate {
view.addSubview(drawingView)

colorSlider.previewEnabled = true
colorSlider.orientation = .Vertical
colorSlider.addTarget(self, action: #selector(ViewController.willChangeColor(_:)), forControlEvents: .TouchDown)
colorSlider.addTarget(self, action: #selector(ViewController.isChangingColor(_:)), forControlEvents: .ValueChanged)
colorSlider.addTarget(self, action: #selector(ViewController.didChangeColor(_:)), forControlEvents: .TouchUpOutside)
colorSlider.addTarget(self, action: #selector(ViewController.didChangeColor(_:)), forControlEvents: .TouchUpInside)
colorSlider.orientation = .vertical
colorSlider.addTarget(self, action: #selector(ViewController.willChangeColor(_:)), for: .touchDown)
colorSlider.addTarget(self, action: #selector(ViewController.isChangingColor(_:)), for: .valueChanged)
colorSlider.addTarget(self, action: #selector(ViewController.didChangeColor(_:)), for: .touchUpOutside)
colorSlider.addTarget(self, action: #selector(ViewController.didChangeColor(_:)), for: .touchUpInside)
view.addSubview(colorSlider)

undoItem = UIBarButtonItem(title: "Undo", style: .Plain, target: self, action: #selector(ViewController.undo))
shareItem = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: #selector(ViewController.share))
undoItem = UIBarButtonItem(title: "Undo", style: .plain, target: self, action: #selector(ViewController.undo))
shareItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(ViewController.share))

let flexibleSpacingItem = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)
undoItem.enabled = false
selectedColorView.backgroundColor = UIColor.blackColor()
let flexibleSpacingItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
undoItem.isEnabled = false
selectedColorView.backgroundColor = UIColor.black
selectedColorItem.width = 30
toolbar.items = [undoItem, flexibleSpacingItem, selectedColorItem, flexibleSpacingItem, shareItem]
view.addSubview(toolbar)
Expand All @@ -96,7 +96,7 @@ class ViewController: UIViewController, ACEDrawingViewDelegate {

selectedColorView.frame = CGRect(x: 0, y: 0, width: selectedColorItem.width, height: selectedColorItem.width)
selectedColorView.layer.cornerRadius = selectedColorView.frame.width / 2.0
selectedColorView.layer.borderColor = UIColor.blackColor().colorWithAlphaComponent(0.3).CGColor
selectedColorView.layer.borderColor = UIColor.black.withAlphaComponent(0.3).cgColor
selectedColorView.layer.borderWidth = 1.0
selectedColorView.clipsToBounds = true
}
Expand All @@ -108,27 +108,27 @@ class ViewController: UIViewController, ACEDrawingViewDelegate {


// MARK: - ColorSlider Events
func willChangeColor(slider: ColorSlider) {
drawingView.userInteractionEnabled = false
func willChangeColor(_ slider: ColorSlider) {
drawingView.isUserInteractionEnabled = false
}

func isChangingColor(slider: ColorSlider) {
func isChangingColor(_ slider: ColorSlider) {
// Respond to a change in color.
}

func didChangeColor(slider: ColorSlider) {
func didChangeColor(_ slider: ColorSlider) {
updateColorViews(slider.color)
drawingView.userInteractionEnabled = true
drawingView.isUserInteractionEnabled = true
}

func updateColorViews(color: UIColor) {
func updateColorViews(_ color: UIColor) {
selectedColorView.backgroundColor = color
drawingView.lineColor = color
}


// MARK: - ACEDrawingView Delegate
func drawingView(view: ACEDrawingView, didEndDrawUsingTool tool: AnyObject) {
func drawingView(_ view: ACEDrawingView, didEndDrawUsingTool tool: AnyObject) {
updateButtons()
}

Expand All @@ -139,23 +139,23 @@ class ViewController: UIViewController, ACEDrawingViewDelegate {
}

func updateButtons() {
undoItem.enabled = drawingView.canUndo()
shareItem.enabled = drawingView.canUndo()
undoItem.isEnabled = drawingView.canUndo()
shareItem.isEnabled = drawingView.canUndo()
}

func share() {
let trimmedImage = drawingView.image.imageByTrimmingTransparentPixels()
let controller = UIActivityViewController(activityItems: [trimmedImage], applicationActivities: nil)
let trimmedImage = drawingView.image.trimmingTransparentPixels()
let controller = UIActivityViewController(activityItems: [trimmedImage!], applicationActivities: nil)
controller.completionWithItemsHandler = {
activityType, completed, returnedItems, activityError in
if completed {
self.drawingView.clear()
self.drawingView.lineColor = UIColor.blackColor()
self.selectedColorView.backgroundColor = UIColor.blackColor()
self.drawingView.lineColor = UIColor.black
self.selectedColorView.backgroundColor = UIColor.black
self.updateButtons()
}
}
controller.popoverPresentationController?.barButtonItem = shareItem
presentViewController(controller, animated: true, completion: nil)
present(controller, animated: true, completion: nil)
}
}
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Inspired by Snapchat, ColorSlider lets you drag vertically to pick a range of co

![Pod Version](https://img.shields.io/cocoapods/v/ColorSlider.svg) [![Build Status](https://travis-ci.org/gizmosachin/ColorSlider.svg?branch=master)](https://travis-ci.org/gizmosachin/ColorSlider)

## Version Compatibility

Current Swift compatibility breakdown:

| Swift Version | Framework Version |
| ------------- | ----------------- |
| 3.0 | master |
| 2.3 | 2.5.1 |

## Usage

Expand All @@ -21,18 +29,18 @@ view.addSubview(colorSlider)

ColorSlider is a subclass of `UIControl` and supports the following `UIControlEvents`:

- `.TouchDown`
- `.ValueChanged`
- `.TouchUpInside`
- `.TouchUpOutside`
- `.TouchCancel`
- `.touchDown`
- `.valueChanged`
- `.touchUpInside`
- `.touchUpOutside`
- `.touchCancel`

You can get the currently selected color with the `color` property.

``` Swift
colorSlider.addTarget(self, action: #selector(ViewController.changedColor(_:)), forControlEvents: .ValueChanged)
colorSlider.addTarget(self, action: #selector(ViewController.changedColor(_:)), forControlEvents: .valueChanged)

func changedColor(slider: ColorSlider) {
func changedColor(_ slider: ColorSlider) {
var color = slider.color
// ...
}
Expand All @@ -47,7 +55,7 @@ colorSlider.previewEnabled = true
Use a horizontal slider:

```swift
colorSlider.orientation = .Horizontal
colorSlider.orientation = .horizontal
```

Customize appearance attributes:
Expand All @@ -69,15 +77,15 @@ ColorSlider is available for installation using [CocoaPods](http://cocoapods.org
platform :ios, '9.0'
use_frameworks!

pod 'ColorSlider', '~> 2.5'
pod 'ColorSlider', '~> 3.0'
```

### Carthage

ColorSlider is also available for installation using [Carthage](https://github.com/Carthage/Carthage). To integrate, add the following to your `Cartfile`:

``` odgl
github "gizmosachin/ColorSlider" >= 2.5
github "gizmosachin/ColorSlider" >= 3.0
```

### Swift Package Manager
Expand Down Expand Up @@ -107,7 +115,7 @@ ColorSlider comes with an example project called Sketchpad, a simple drawing app

ColorSlider uses [HSB](https://en.wikipedia.org/wiki/HSB) and defaults to a saturation and brightness: 100%.

When the `orientation` is set to `.Vertical`, dragging vertically adjusts the hue, and dragging outside adjusts the saturation and brightness as follows:
When the `orientation` is set to `.vertical`, dragging vertically adjusts the hue, and dragging outside adjusts the saturation and brightness as follows:

- Inside the frame, dragging vertically adjusts the hue
- Outside the frame, dragging horizontally adjusts the saturation
Expand Down
Loading

0 comments on commit fa7a40e

Please sign in to comment.