From f517c96f00becf9653a2fc3f5031c858724ae56e Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Mon, 18 Sep 2017 11:15:17 +0800 Subject: [PATCH 1/6] Update to xcode9.0 and swift4.0 --- CalculatorKeyboard.xcodeproj/project.pbxproj | 25 +++- .../xcschemes/CalculatorKeyboard.xcscheme | 4 +- CalculatorKeyboard/CalculatorKeyboard.swift | 32 ++--- CalculatorKeyboard/CalculatorKeyboard.xib | 129 ++++++++---------- CalculatorKeyboard/CalculatorProcessor.swift | 30 ++-- Example/Example.xcodeproj/project.pbxproj | 2 + Example/Example/AppDelegate.swift | 12 +- Example/Example/Base.lproj/Main.storyboard | 19 +-- Example/Example/ViewController.swift | 6 +- 9 files changed, 137 insertions(+), 122 deletions(-) diff --git a/CalculatorKeyboard.xcodeproj/project.pbxproj b/CalculatorKeyboard.xcodeproj/project.pbxproj index f331d01..7fcfa52 100644 --- a/CalculatorKeyboard.xcodeproj/project.pbxproj +++ b/CalculatorKeyboard.xcodeproj/project.pbxproj @@ -155,7 +155,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Reefactor, Inc."; TargetAttributes = { 45C5244D1C120F4E00510CF7 = { @@ -240,13 +240,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_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_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -274,6 +282,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -288,13 +297,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_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_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -314,6 +331,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -325,6 +344,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -336,6 +356,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -343,6 +364,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -353,6 +375,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.reefactor.CalculatorKeyboard; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/CalculatorKeyboard.xcodeproj/xcshareddata/xcschemes/CalculatorKeyboard.xcscheme b/CalculatorKeyboard.xcodeproj/xcshareddata/xcschemes/CalculatorKeyboard.xcscheme index d160922..bfd4d8d 100644 --- a/CalculatorKeyboard.xcodeproj/xcshareddata/xcschemes/CalculatorKeyboard.xcscheme +++ b/CalculatorKeyboard.xcodeproj/xcshareddata/xcschemes/CalculatorKeyboard.xcscheme @@ -1,6 +1,6 @@ UIView { - let bundle = NSBundle(forClass: self.dynamicType) + let bundle = Bundle(for: type(of: self)) let nib = UINib(nibName: "CalculatorKeyboard", bundle: bundle) - let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView + let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView adjustButtonConstraint() return view } @@ -114,37 +114,37 @@ public class CalculatorKeyboard: UIView { adjustButtonConstraint() } - for var i = 1; i <= CalculatorKey.Decimal.rawValue; i++ { + for i in 1...CalculatorKey.Decimal.rawValue { if let button = self.view.viewWithTag(i) as? UIButton { button.tintColor = numbersBackgroundColor - button.setTitleColor(numbersTextColor, forState: .Normal) + button.setTitleColor(numbersTextColor, for: .normal) } } - for var i = CalculatorKey.Clear.rawValue; i <= CalculatorKey.Add.rawValue; i++ { + for i in CalculatorKey.Clear.rawValue...CalculatorKey.Add.rawValue { if let button = self.view.viewWithTag(i) as? UIButton { button.tintColor = operationsBackgroundColor - button.setTitleColor(operationsTextColor, forState: .Normal) + button.setTitleColor(operationsTextColor, for: .normal) button.tintColor = operationsTextColor } } if let button = self.view.viewWithTag(CalculatorKey.Equal.rawValue) as? UIButton { button.tintColor = equalBackgroundColor - button.setTitleColor(equalTextColor, forState: .Normal) + button.setTitleColor(equalTextColor, for: .normal) } } private func adjustButtonConstraint() { - let width = UIScreen.mainScreen().bounds.width / 4.0 + let width = UIScreen.main.bounds.width / 4.0 zeroDistanceConstraint.constant = showDecimal ? width + 2.0 : 1.0 layoutIfNeeded() } - @IBAction func buttonPressed(sender: UIButton) { + @IBAction func buttonPressed(_ sender: UIButton) { switch (sender.tag) { case (CalculatorKey.Zero.rawValue)...(CalculatorKey.Nine.rawValue): - let output = processor.storeOperand(sender.tag-1) + let output = processor.storeOperand(value: sender.tag-1) delegate?.calculator(self, didChangeValue: output) case CalculatorKey.Decimal.rawValue: let output = processor.addDecimal() @@ -156,7 +156,7 @@ public class CalculatorKeyboard: UIView { let output = processor.deleteLastDigit() delegate?.calculator(self, didChangeValue: output) case (CalculatorKey.Multiply.rawValue)...(CalculatorKey.Add.rawValue): - let output = processor.storeOperator(sender.tag) + let output = processor.storeOperator(rawValue: sender.tag) delegate?.calculator(self, didChangeValue: output) case CalculatorKey.Equal.rawValue: let output = processor.computeFinalValue() diff --git a/CalculatorKeyboard/CalculatorKeyboard.xib b/CalculatorKeyboard/CalculatorKeyboard.xib index d5e5285..986975b 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.xib +++ b/CalculatorKeyboard/CalculatorKeyboard.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -16,12 +20,11 @@ - - - - - + diff --git a/CalculatorKeyboard/CalculatorProcessor.swift b/CalculatorKeyboard/CalculatorProcessor.swift index 3b172d2..48b1dc2 100644 --- a/CalculatorKeyboard/CalculatorProcessor.swift +++ b/CalculatorKeyboard/CalculatorProcessor.swift @@ -41,12 +41,12 @@ class CalculatorProcessor { } if automaticDecimal { - currentOperand = currentOperand.stringByReplacingOccurrencesOfString(decimalSymbol(), withString: "") + currentOperand = currentOperand.replacingOccurrences(of: decimalSymbol(), with: "") if currentOperand[currentOperand.startIndex] == "0" { - currentOperand.removeAtIndex(currentOperand.startIndex) + currentOperand.remove(at: currentOperand.startIndex) } let char = decimalSymbol()[decimalSymbol().startIndex] - currentOperand.insert(char, atIndex: currentOperand.endIndex.advancedBy(-2)) + currentOperand.insert(char, at: currentOperand.index(currentOperand.startIndex, offsetBy: -2)) } return currentOperand @@ -54,15 +54,15 @@ class CalculatorProcessor { func deleteLastDigit() -> String { if currentOperand.characters.count > 1 { - currentOperand.removeAtIndex(currentOperand.endIndex.predecessor()) + currentOperand.remove(at: currentOperand.index(before: currentOperand.endIndex)) if automaticDecimal { - currentOperand = currentOperand.stringByReplacingOccurrencesOfString(decimalSymbol(), withString: "") + currentOperand = currentOperand.replacingOccurrences(of: decimalSymbol(), with: "") if currentOperand.characters.count < 3 { - currentOperand.insert("0", atIndex: currentOperand.startIndex) + currentOperand.insert("0", at: currentOperand.startIndex) } let char = decimalSymbol()[decimalSymbol().startIndex] - currentOperand.insert(char, atIndex: currentOperand.endIndex.advancedBy(-2)) + currentOperand.insert(char, at: currentOperand.index(currentOperand.startIndex, offsetBy: -2)) } } else { currentOperand = resetOperand() @@ -72,7 +72,7 @@ class CalculatorProcessor { } func addDecimal() -> String { - if currentOperand.rangeOfString(decimalSymbol()) == nil { + if currentOperand.range(of: decimalSymbol()) == nil { currentOperand += decimalSymbol() } return currentOperand @@ -110,7 +110,7 @@ class CalculatorProcessor { default: break } - currentOperand = formatValue(output) + currentOperand = formatValue(value: output) } previousOperand = resetOperand() storedOperator = .Equal @@ -131,7 +131,7 @@ class CalculatorProcessor { private func resetOperand() -> String { var operand = "0" if automaticDecimal { - operand = convertOperandToDecimals(operand) + operand = convertOperandToDecimals(operand: operand) } return operand } @@ -146,12 +146,12 @@ class CalculatorProcessor { raw = String(format: "%.2f", value) return raw } else { - var end = raw.endIndex.predecessor() + var end = raw.index(before: raw.endIndex) var foundDecimal = false - while end != raw.startIndex && (raw[end] == "0" || isDecimal(raw[end])) && !foundDecimal { - foundDecimal = isDecimal(raw[end]) - raw.removeAtIndex(end) - end = end.predecessor() + while end != raw.startIndex && (raw[end] == "0" || isDecimal(char: raw[end])) && !foundDecimal { + foundDecimal = isDecimal(char: raw[end]) + raw.remove(at: end) + end = raw.index(before: raw.endIndex) } return raw } diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index bd13831..d02c432 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -378,6 +378,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -414,6 +415,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.4; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 4.0; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index e6d780b..5024eab 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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:. } diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index 119e969..5b4415a 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -1,7 +1,12 @@ - - + + + + + - + + + @@ -13,12 +18,11 @@ - + - - + @@ -26,8 +30,7 @@ - - + diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index d48d34b..bec1a8d 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -15,14 +15,14 @@ class ViewController: UIViewController, CalculatorDelegate { override func viewDidLoad() { super.viewDidLoad() - let frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 300) + let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300) let keyboard = CalculatorKeyboard(frame: frame) keyboard.delegate = self keyboard.showDecimal = true inputTextField.inputView = keyboard } - override func viewDidAppear(animated: Bool) { + override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) inputTextField.becomeFirstResponder() } @@ -32,7 +32,7 @@ class ViewController: UIViewController, CalculatorDelegate { } // MARK: - RFCalculatorKeyboard delegate - func calculator(calculator: CalculatorKeyboard, didChangeValue value: String) { + func calculator(_: CalculatorKeyboard, didChangeValue value: String) { inputTextField.text = value } } From 39c35fecc4eb5aa05e122a3060b0692b096ea652 Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Mon, 18 Sep 2017 11:16:54 +0800 Subject: [PATCH 2/6] Add default frame --- CalculatorKeyboard/CalculatorKeyboard.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CalculatorKeyboard/CalculatorKeyboard.swift b/CalculatorKeyboard/CalculatorKeyboard.swift index c33fd59..4f780d7 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.swift +++ b/CalculatorKeyboard/CalculatorKeyboard.swift @@ -88,6 +88,10 @@ public class CalculatorKeyboard: UIView { loadXib() } + convenience init() { + self.init(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300)) + } + public override func awakeFromNib() { super.awakeFromNib() adjustLayout() From a9b74225c08b1393e94c2aa9b62e4f3dbd7d2345 Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Mon, 18 Sep 2017 13:42:08 +0800 Subject: [PATCH 3/6] Add toggle sign --- CalculatorKeyboard/CalculatorKeyboard.swift | 8 ++- CalculatorKeyboard/CalculatorKeyboard.xib | 52 +++++++++++++------- CalculatorKeyboard/CalculatorProcessor.swift | 12 +++++ 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/CalculatorKeyboard/CalculatorKeyboard.swift b/CalculatorKeyboard/CalculatorKeyboard.swift index 4f780d7..d2fa6ba 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.swift +++ b/CalculatorKeyboard/CalculatorKeyboard.swift @@ -13,7 +13,8 @@ public protocol CalculatorDelegate: class { } enum CalculatorKey: Int { - case Zero = 1 + case Sign + case Zero case One case Two case Three @@ -147,8 +148,11 @@ public class CalculatorKeyboard: UIView { @IBAction func buttonPressed(_ sender: UIButton) { switch (sender.tag) { + case CalculatorKey.Sign.rawValue: + let output = processor.toggleSign() + delegate?.calculator(self, didChangeValue: output) case (CalculatorKey.Zero.rawValue)...(CalculatorKey.Nine.rawValue): - let output = processor.storeOperand(value: sender.tag-1) + let output = processor.storeOperand(value: sender.tag - 1) delegate?.calculator(self, didChangeValue: output) case CalculatorKey.Decimal.rawValue: let output = processor.addDecimal() diff --git a/CalculatorKeyboard/CalculatorKeyboard.xib b/CalculatorKeyboard/CalculatorKeyboard.xib index 986975b..34e7732 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.xib +++ b/CalculatorKeyboard/CalculatorKeyboard.xib @@ -11,7 +11,7 @@ - + @@ -20,7 +20,7 @@ - + + @@ -229,6 +241,7 @@ + @@ -242,10 +255,12 @@ + + @@ -255,7 +270,9 @@ + + @@ -276,14 +293,15 @@ + + - diff --git a/CalculatorKeyboard/CalculatorProcessor.swift b/CalculatorKeyboard/CalculatorProcessor.swift index 48b1dc2..0fc0122 100644 --- a/CalculatorKeyboard/CalculatorProcessor.swift +++ b/CalculatorKeyboard/CalculatorProcessor.swift @@ -23,6 +23,18 @@ class CalculatorProcessor { var decimalDigit = 0 + func toggleSign() -> String { + if currentOperand != "0" { + if currentOperand.starts(with: "-") { + let startIndex = currentOperand.index(currentOperand.startIndex, offsetBy: 1) + currentOperand = String(currentOperand[startIndex...]) + } else { + currentOperand = "-" + currentOperand + } + } + return currentOperand + } + func storeOperand(value: Int) -> String { let operand = "\(value)" if currentOperand == "0" { From 949ae86a02a777fdfe929e3ada55ca600c34dd92 Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Mon, 18 Sep 2017 16:23:45 +0800 Subject: [PATCH 4/6] set deployment target to 8.0 --- CalculatorKeyboard.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CalculatorKeyboard.xcodeproj/project.pbxproj b/CalculatorKeyboard.xcodeproj/project.pbxproj index 7fcfa52..907cd8a 100644 --- a/CalculatorKeyboard.xcodeproj/project.pbxproj +++ b/CalculatorKeyboard.xcodeproj/project.pbxproj @@ -277,7 +277,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -328,7 +328,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; From 3099b90eff72f535c4e8bcfe0c61ca0ffcb4f93b Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Mon, 18 Sep 2017 17:42:29 +0800 Subject: [PATCH 5/6] Adjust nib constraints --- CalculatorKeyboard/CalculatorKeyboard.swift | 11 - CalculatorKeyboard/CalculatorKeyboard.xib | 284 ++++++++++---------- 2 files changed, 139 insertions(+), 156 deletions(-) diff --git a/CalculatorKeyboard/CalculatorKeyboard.swift b/CalculatorKeyboard/CalculatorKeyboard.swift index d2fa6ba..54f1222 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.swift +++ b/CalculatorKeyboard/CalculatorKeyboard.swift @@ -110,15 +110,10 @@ public class CalculatorKeyboard: UIView { let bundle = Bundle(for: type(of: self)) let nib = UINib(nibName: "CalculatorKeyboard", bundle: bundle) let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView - adjustButtonConstraint() return view } private func adjustLayout() { - if viewWithTag(CalculatorKey.Decimal.rawValue) != nil { - adjustButtonConstraint() - } - for i in 1...CalculatorKey.Decimal.rawValue { if let button = self.view.viewWithTag(i) as? UIButton { button.tintColor = numbersBackgroundColor @@ -140,12 +135,6 @@ public class CalculatorKeyboard: UIView { } } - private func adjustButtonConstraint() { - let width = UIScreen.main.bounds.width / 4.0 - zeroDistanceConstraint.constant = showDecimal ? width + 2.0 : 1.0 - layoutIfNeeded() - } - @IBAction func buttonPressed(_ sender: UIButton) { switch (sender.tag) { case CalculatorKey.Sign.rawValue: diff --git a/CalculatorKeyboard/CalculatorKeyboard.xib b/CalculatorKeyboard/CalculatorKeyboard.xib index 34e7732..0c82a90 100644 --- a/CalculatorKeyboard/CalculatorKeyboard.xib +++ b/CalculatorKeyboard/CalculatorKeyboard.xib @@ -9,51 +9,47 @@ - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + From e20a05d87854a595fb80635b79c9de842f87d693 Mon Sep 17 00:00:00 2001 From: "S.Lance" Date: Sun, 3 Dec 2017 16:31:47 +0800 Subject: [PATCH 6/6] Bumped version to 1.2.0 --- CalculatorKeyboard/Info.plist | 2 +- Example/Example/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CalculatorKeyboard/Info.plist b/CalculatorKeyboard/Info.plist index 09bc972..331a2da 100644 --- a/CalculatorKeyboard/Info.plist +++ b/CalculatorKeyboard/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.0 + 1.2.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Example/Info.plist b/Example/Example/Info.plist index 7668538..7192165 100644 --- a/Example/Example/Info.plist +++ b/Example/Example/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1.0 + 1.2.0 CFBundleSignature ???? CFBundleVersion