Skip to content

Commit

Permalink
convert to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhiyi1992 committed Nov 6, 2016
1 parent c7a8e58 commit bbfd6d1
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 170 deletions.
3 changes: 3 additions & 0 deletions SpreadButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
TargetAttributes = {
488D7ACB1C4CDD59007957F0 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -309,6 +310,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SpreadButton/ZYSpreadButton/Classes/SpreadButton-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -323,6 +325,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lzy.SpreadButton;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SpreadButton/ZYSpreadButton/Classes/SpreadButton-Bridging-Header.h";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
12 changes: 6 additions & 6 deletions SpreadButton/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
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
65 changes: 34 additions & 31 deletions SpreadButton/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,46 @@ class ViewController: UIViewController {

configureButtonCorner()

// runWithSwiftCode();
runWithObjcCode();
runWithSwiftCode();
// runWithObjcCode();
}

//ObjC
func runWithObjcCode() {
let btn1 = ZYSpreadSubButton(backgroundImage: UIImage(named: "clock"), highlightImage: UIImage(named: "clock_highlight")) { (index, sender) -> Void in
let btn1 = ZYSpreadSubButton(backgroundImage: UIImage(named: "clock"), highlight: UIImage(named: "clock_highlight")) { (index, sender) -> Void in
print("\(index+1)个按钮被按了")
}

let btn2 = ZYSpreadSubButton(backgroundImage: UIImage(named: "pencil"), highlightImage: UIImage(named: "pencil_highlight")) { (index, sender) -> Void in
let btn2 = ZYSpreadSubButton(backgroundImage: UIImage(named: "pencil"), highlight: UIImage(named: "pencil_highlight")) { (index, sender) -> Void in
print("\(index+1)个按钮被按了")
}


let btn3 = ZYSpreadSubButton(backgroundImage: UIImage(named: "juice"), highlightImage: UIImage(named: "juice_highlight")) { (index, sender) -> Void in
let btn3 = ZYSpreadSubButton(backgroundImage: UIImage(named: "juice"), highlight: UIImage(named: "juice_highlight")) { (index, sender) -> Void in
print("\(index+1)个按钮被按了")
}


let btn4 = ZYSpreadSubButton(backgroundImage: UIImage(named: "service"), highlightImage: UIImage(named: "service_highlight")) { (index, sender) -> Void in
let btn4 = ZYSpreadSubButton(backgroundImage: UIImage(named: "service"), highlight: UIImage(named: "service_highlight")) { (index, sender) -> Void in
print("\(index+1)个按钮被按了")
}


let btn5 = ZYSpreadSubButton(backgroundImage: UIImage(named: "shower"), highlightImage: UIImage(named: "shower_highlight")) { (index, sender) -> Void in
let btn5 = ZYSpreadSubButton(backgroundImage: UIImage(named: "shower"), highlight: UIImage(named: "shower_highlight")) { (index, sender) -> Void in
print("\(index+1)个按钮被按了")
}

let zySpreadButton = ZYSpreadButton(backgroundImage: UIImage(named: "powerButton"), highlightImage: UIImage(named: "powerButton_highlight"), position: CGPointMake(40, UIScreen.mainScreen().bounds.height - 40))
let zySpreadButton = ZYSpreadButton(backgroundImage: UIImage(named: "powerButton"), highlight: UIImage(named: "powerButton_highlight"), position: CGPoint(x: 40, y: UIScreen.main.bounds.height - 40))
self.zySpreadButton = zySpreadButton;

zySpreadButton.subButtons = [btn1, btn2, btn3, btn4, btn5]
zySpreadButton.mode = SpreadModeSickleSpread
zySpreadButton.direction = SpreadDirectionRightUp
zySpreadButton.radius = 120
zySpreadButton.positionMode = SpreadPositionModeFixed
guard let button1 = btn1, let button2 = btn2, let button3 = btn3, let button4 = btn4, let button5 = btn5 else {
return;
}
zySpreadButton?.subButtons = [button1, button2, button3, button4, button5]
zySpreadButton?.mode = SpreadModeSickleSpread
zySpreadButton?.direction = SpreadDirectionRightUp
zySpreadButton?.radius = 120
zySpreadButton?.positionMode = SpreadPositionModeFixed

/* and you can assign a newValue to change the default
spreadButton?.animationDuring = 0.2
Expand All @@ -69,13 +72,13 @@ class ViewController: UIViewController {


//you can assign the Blocks like this
zySpreadButton.buttonWillSpreadBlock = { print("\(CGRectGetMaxY($0.frame)) will spread") }
zySpreadButton.buttonDidSpreadBlock = { _ in print("did spread") }
zySpreadButton.buttonWillCloseBlock = { _ in print("will closed") }
zySpreadButton.buttonDidCloseBlock = { _ in print("did closed") }
zySpreadButton?.buttonWillSpreadBlock = { print("\($0?.frame.maxY) will spread") }
zySpreadButton?.buttonDidSpreadBlock = { _ in print("did spread") }
zySpreadButton?.buttonWillCloseBlock = { _ in print("will closed") }
zySpreadButton?.buttonDidCloseBlock = { _ in print("did closed") }

if zySpreadButton != nil {
self.view.addSubview(zySpreadButton)
self.view.addSubview(zySpreadButton!)
}
}

Expand Down Expand Up @@ -104,14 +107,14 @@ class ViewController: UIViewController {

let spreadButton = SpreadButton(image: UIImage(named: "powerButton"),
highlightImage: UIImage(named: "powerButton_highlight"),
position: CGPointMake(40, UIScreen.mainScreen().bounds.height - 40))
position: CGPoint(x: 40, y: UIScreen.main.bounds.height - 40))
self.spreadButton = spreadButton

spreadButton?.setSubButtons([btn1, btn2, btn3, btn4, btn5])
spreadButton?.mode = SpreadMode.SpreadModeSickleSpread
spreadButton?.direction = SpreadDirection.SpreadDirectionRightUp
spreadButton?.mode = SpreadMode.spreadModeSickleSpread
spreadButton?.direction = SpreadDirection.spreadDirectionRightUp
spreadButton?.radius = 120
spreadButton?.positionMode = SpreadPositionMode.SpreadPositionModeFixed
spreadButton?.positionMode = SpreadPositionMode.spreadPositionModeFixed

/* and you can assign a newValue to change the default
spreadButton?.animationDuring = 0.2
Expand All @@ -123,7 +126,7 @@ class ViewController: UIViewController {
*/

//you can assign the Blocks like this
spreadButton?.buttonWillSpreadBlock = { print(CGRectGetMaxY($0.frame)) }
spreadButton?.buttonWillSpreadBlock = { print($0.frame.maxY) }
spreadButton?.buttonDidSpreadBlock = { _ in print("did spread") }
spreadButton?.buttonWillCloseBlock = { _ in print("will closed") }
spreadButton?.buttonDidCloseBlock = { _ in print("did closed") }
Expand All @@ -133,27 +136,27 @@ class ViewController: UIViewController {
}
}

@IBAction func changePositionMode(sender: AnyObject) {
@IBAction func changePositionMode(_ sender: AnyObject) {

//display with Swift Code
if spreadButton != nil {
if spreadButton?.positionMode == SpreadPositionMode.SpreadPositionModeFixed {
spreadButton?.positionMode = SpreadPositionMode.SpreadPositionModeTouchBorder
sender.setTitle(" ModeTouchBorder ", forState: .Normal)
if spreadButton?.positionMode == SpreadPositionMode.spreadPositionModeFixed {
spreadButton?.positionMode = SpreadPositionMode.spreadPositionModeTouchBorder
sender.setTitle(" ModeTouchBorder ", for: UIControlState())
} else {
spreadButton?.positionMode = SpreadPositionMode.SpreadPositionModeFixed
sender.setTitle(" ModeFixed ", forState: .Normal)
spreadButton?.positionMode = SpreadPositionMode.spreadPositionModeFixed
sender.setTitle(" ModeFixed ", for: UIControlState())
}
}

//display with OC Code
if zySpreadButton != nil {
if zySpreadButton.positionMode == SpreadPositionModeFixed {
zySpreadButton.positionMode = SpreadPositionModeTouchBorder
sender.setTitle(" ModeTouchBorder ", forState: .Normal)
sender.setTitle(" ModeTouchBorder ", for: UIControlState())
} else {
zySpreadButton.positionMode = SpreadPositionModeFixed
sender.setTitle(" ModeFixed ", forState: .Normal)
sender.setTitle(" ModeFixed ", for: UIControlState())
}
}
}
Expand Down
Loading

0 comments on commit bbfd6d1

Please sign in to comment.