Skip to content

Commit

Permalink
Swift 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Sep 21, 2016
1 parent a396b61 commit a2a4153
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 274 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SegmentedControl is a highly customizable segmented control for iOS application

##How To Get Started
###Carthage
Specify "SegmentedControl" in your Cartfile:
Specify "SegmentedControl" in your ```Cartfile```:
```ogdl
github "teambition/SegmentedControl"
```
Expand All @@ -24,17 +24,17 @@ let segmentedControl = SegmentedControl.initWithTitles(titles, selectedTitles: s
// assign delegate
segmentedControl.delegate = self

// configure selection box if needed, the default style is 'None'
segmentedControl.selectionBoxStyle = .Default
// configure selection box if needed, the default style is 'none'
segmentedControl.selectionBoxStyle = .default
segmentedControl.selectionBoxColor = UIColor(white: 0.62, alpha: 1)
segmentedControl.selectionBoxCornerRadius = 15 // default is 0
segmentedControl.selectionBoxEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 20) // default is UIEdgeInsetsZero
segmentedControl.selectionBoxEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // default is UIEdgeInsets.zero

// configure selection indicator if needed, the default style is 'None'
segmentedControl.selectionIndicatorStyle = .Top
// configure selection indicator if needed, the default style is 'none'
segmentedControl.selectionIndicatorStyle = .top
segmentedControl.selectionIndicatorColor = UIColor(white: 0.3, alpha: 1)
segmentedControl.selectionIndicatorHeight = 3 // default is 5
segmentedControl.selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 20) // default is UIEdgeInsetsZero
segmentedControl.selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // default is UIEdgeInsets.zero
```

##### Image
Expand All @@ -50,22 +50,26 @@ let segmentedControl = SegmentedControl.initWithImages(images, selectedImages: s
// assign delegate
segmentedControl.delegate = self

// configure selection box if needed, the default style is 'None'
segmentedControl.selectionBoxStyle = .Default
segmentedControl.selectionBoxColor = UIColor.lightGrayColor()
// configure selection box if needed, the default style is 'none'
segmentedControl.selectionBoxStyle = .default
segmentedControl.selectionBoxColor = UIColor.lightGray
segmentedControl.selectionBoxCornerRadius = 15 // default is 0
segmentedControl.selectionBoxEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 20) // default is UIEdgeInsetsZero
segmentedControl.selectionBoxEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // default is UIEdgeInsets.zero

// configure selection indicator if needed, the default style is 'None'
segmentedControl.selectionIndicatorStyle = .Bottom
segmentedControl.selectionIndicatorColor = UIColor.darkGrayColor()
// configure selection indicator if needed, the default style is 'none'
segmentedControl.selectionIndicatorStyle = .bottom
segmentedControl.selectionIndicatorColor = UIColor.darkGray
segmentedControl.selectionIndicatorHeight = 3 // default is 5
segmentedControl.selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 20) // default is UIEdgeInsetsZero
segmentedControl.selectionIndicatorEdgeInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // default is UIEdgeInsets.zero
```

##### Implement delegate
```swift
func segmentedControl(segmentedControl: SegmentedControl, didSelectIndex selectedIndex: Int) {
func segmentedControl(_ segmentedControl: SegmentedControl, didSelectIndex selectedIndex: Int) {
// do something
}

func segmentedControl(_ segmentedControl: SegmentedControl, didLongPressIndex longPressIndex: Int) {
// do something
}
```
Expand Down
12 changes: 11 additions & 1 deletion SegmentedControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@
D3E3B0C21C3282BB003EAA6E /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Teambition;
TargetAttributes = {
D3E3B0CA1C3282BB003EAA6E = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -169,8 +170,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -217,8 +220,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -238,6 +243,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -249,6 +255,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -260,13 +267,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
D3E3B0D51C3282BB003EAA6E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -277,6 +286,7 @@
PRODUCT_BUNDLE_IDENTIFIER = Teambition.SegmentedControl;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.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 = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions SegmentedControl/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import UIKit

struct SelectionIndicator {
internal struct SelectionIndicator {
static let defaultHeight: CGFloat = 5
}
}
32 changes: 16 additions & 16 deletions SegmentedControl/SCScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@

import UIKit

class SCScrollView: UIScrollView {
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if !dragging {
nextResponder()?.touchesBegan(touches, withEvent: event)
internal class SCScrollView: UIScrollView {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if !isDragging {
next?.touchesBegan(touches, with: event)
} else {
super.touchesBegan(touches, withEvent: event)
super.touchesBegan(touches, with: event)
}
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if !dragging {
nextResponder()?.touchesMoved(touches, withEvent: event)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if !isDragging {
next?.touchesMoved(touches, with: event)
} else {
super.touchesMoved(touches, withEvent: event)
super.touchesMoved(touches, with: event)
}
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if !dragging {
nextResponder()?.touchesEnded(touches, withEvent: event)
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if !isDragging {
next?.touchesEnded(touches, with: event)
} else {
super.touchesEnded(touches, withEvent: event)
super.touchesEnded(touches, with: event)
}
}
}

extension SCScrollView {
var parentViewController: UIViewController? {
internal extension SCScrollView {
internal var parentViewController: UIViewController? {
var parentResponder: UIResponder? = self
while parentResponder != nil {
parentResponder = parentResponder!.nextResponder()
parentResponder = parentResponder!.next
if let viewController = parentResponder as? UIViewController {
return viewController
}
Expand Down
Loading

0 comments on commit a2a4153

Please sign in to comment.