From da2ccaa918f863a87cdc4fc0bd6458ffb62c0ae4 Mon Sep 17 00:00:00 2001 From: Lee <18611401994@163.com> Date: Thu, 22 Oct 2020 15:32:18 +0800 Subject: [PATCH] =?UTF-8?q?2.1.0=20=E4=BC=98=E5=8C=96API=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoInch.podspec | 2 +- AutoInch.xcodeproj/project.pbxproj | 4 +-- Demo/Demo/ViewController.swift | 24 +++++++++--------- README.md | 24 +++++++++--------- README_CN.md | 25 +++++++++---------- Sources/Screen.swift | 40 +++++++++++++++--------------- 6 files changed, 59 insertions(+), 60 deletions(-) diff --git a/AutoInch.podspec b/AutoInch.podspec index b3dbc19..9b622ba 100644 --- a/AutoInch.podspec +++ b/AutoInch.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "AutoInch" -s.version = "2.0.1" +s.version = "2.1.0" s.summary = "优雅的iPhone 等比例/精准 适配工具" s.homepage = "https://github.com/lixiang1994/AutoInch" diff --git a/AutoInch.xcodeproj/project.pbxproj b/AutoInch.xcodeproj/project.pbxproj index 13ed7db..8c0bdc5 100644 --- a/AutoInch.xcodeproj/project.pbxproj +++ b/AutoInch.xcodeproj/project.pbxproj @@ -287,7 +287,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.1.0; OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = com.lee.autoinch; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -319,7 +319,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 2.0.1; + MARKETING_VERSION = 2.1.0; OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = com.lee.autoinch; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; diff --git a/Demo/Demo/ViewController.swift b/Demo/Demo/ViewController.swift index 5f1a09f..958f20c 100644 --- a/Demo/Demo/ViewController.swift +++ b/Demo/Demo/ViewController.swift @@ -18,20 +18,20 @@ class ViewController: UITableViewController { print( "this is " + "default".screen - .set("宽度 320", for: .width(._320)) - .set("宽度 375", for: .width(._375)) - .set("高度 844", for: .height(._844)) - .set("高度 812", for: .height(._812)) - .set("4.7 英寸", for: .inch(._4_7)) - .set("5.8 英寸", for: .inch(._5_8)) - .set("6.5 英寸", for: .inch(._6_5)) - .set("屏幕级别 紧凑屏", for: .level(.compact)) - .set("屏幕级别 常规屏", for: .level(.regular)) - .set("屏幕级别 全面屏", for: .level(.full)) + .width(._320, is: "宽度 320") + .width(._375, is: "宽度 375") + .height(._844, is: "高度 844") + .height(._812, is: "高度 812") + .inch(._4_7, is: "4.7 英寸") + .inch(._5_8, is: "5.8 英寸") + .inch(._6_5, is: "6.5 英寸") + .level(.compact, is: "屏幕级别 紧凑屏") + .level(.regular, is: "屏幕级别 常规屏") + .level(.full, is: "屏幕级别 全面屏") .value ) - 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0)).value - print(0.screen.set(1, for: .level(.full)).set(2, for: .inch(._6_1)).value) + 0.screen.inch(._3_5, is: 1).inch(._4_0, is: 2).value + print(0.screen.level(.full, is: 1).inch(._6_1, is: 2).value) print("当前屏幕级别: \(Screen.Level.current)") } diff --git a/README.md b/README.md index 76a47f0..51ca962 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ e.g. // default other screen numberOfLines = 0 // 3.5 inches screen numberOfLines = 1 // 4.0 inches screen numberOfLines = 2 -label.numberOfLines = 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0)).value +label.numberOfLines = 0.screen.inch(._3_5, is: 1).inch(._4_0, is: 2).value ``` @@ -120,23 +120,23 @@ label.numberOfLines = 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0 // default other screen numberOfLines = 0 // width 320 screen numberOfLines = 1 // width 375 inches screen numberOfLines = 2 -label.numberOfLines = 0.screen.set(1, for: .width(._320)).set(2, for: .width(._375)).value +label.numberOfLines = 0.screen.width(._320, is: 1).width(._375, is: 2).value ``` ```swift print("this is " + "default".screen - .set("width 320", for: .width(._320)) - .set("width 375", for: .width(._375)) - .set("height 844", for: .height(._844)) - .set("height 812", for: .height(._812)) - .set("4.7 inches", for: .inch(._4_7)) - .set("5.8 inches", for: .inch(._5_8)) - .set("6.5 inches", for: .inch(._6_5)) - .set("screen 3: 2", for: .level(.compact)) - .set("screen 16: 9", for: .level(.regular)) - .set("screen 19.5: 9", for: .level(.full)) + .width(._320, is: "width 320") + .width(._375, is: "width 375") + .height(._844, is: "height 844") + .height(._812, is: "height 812") + .inch(._4_7, is: "4.7 inches") + .inch(._5_8, is: "5.8 inches") + .inch(._6_5, is: "6.5 inches") + .level(.compact, is: "screen 3: 2") + .level(.regular, is: "screen 16: 9") + .level(.full, is: "screen 19.5: 9") .value ) ``` diff --git a/README_CN.md b/README_CN.md index 6bb344c..7a57a0d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -109,7 +109,7 @@ Storyboard / Xib: // default other screen numberOfLines = 0 // 3.5 inches screen numberOfLines = 1 // 4.0 inches screen numberOfLines = 2 -label.numberOfLines = 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0)).value +label.numberOfLines = 0.screen.inch(._3_5, is: 1).inch(._4_0, is: 2).value ``` @@ -117,24 +117,23 @@ label.numberOfLines = 0.screen.set(1, for: .inch(._3_5)).set(2, for: .inch(._4_0 // default other screen numberOfLines = 0 // width 320 screen numberOfLines = 1 // width 375 inches screen numberOfLines = 2 -label.numberOfLines = 0.screen.set(1, for: .width(._320)).set(2, for: .width(._375)).value +label.numberOfLines = 0.screen.width(._320, is: 1).width(._375, is: 2).value ``` -全部 ```swift print("this is " + "default".screen - .set("宽度 320", for: .width(._320)) - .set("宽度 375", for: .width(._375)) - .set("高度 844", for: .height(._844)) - .set("高度 812", for: .height(._812)) - .set("4.7 英寸", for: .inch(._4_7)) - .set("5.8 英寸", for: .inch(._5_8)) - .set("6.5 英寸", for: .inch(._6_5)) - .set("屏幕级别 紧凑屏", for: .level(.compact)) - .set("屏幕级别 常规屏", for: .level(.regular)) - .set("屏幕级别 全面屏", for: .level(.full)) + .width(._320, is: "宽度 320") + .width(._375, is: "宽度 375") + .height(._844, is: "高度 844") + .height(._812, is: "高度 812") + .inch(._4_7, is: "4.7 英寸") + .inch(._5_8, is: "5.8 英寸") + .inch(._6_5, is: "6.5 英寸") + .level(.compact, is: "屏幕级别 紧凑屏") + .level(.regular, is: "屏幕级别 常规屏") + .level(.full, is: "屏幕级别 全面屏") .value ) ``` diff --git a/Sources/Screen.swift b/Sources/Screen.swift index 4eaee63..14af49d 100644 --- a/Sources/Screen.swift +++ b/Sources/Screen.swift @@ -42,14 +42,29 @@ extension ScreenCompatible { extension ScreenWrapper { - public func set(_ value: Base, for type: Screen) -> Self { - guard type.isCurrent else { return self } - self.value = value + public func width(_ types: Screen.Width... , is value: Base) -> Self { + for type in types where Screen.Width.current == type { + self.value = value + } return self } - public func set(_ value: Base, for types: Screen...) -> Self { - for type in types where type.isCurrent { + public func height(_ types: Screen.Height..., is value: Base) -> Self { + for type in types where Screen.Height.current == type { + self.value = value + } + return self + } + + public func inch(_ types: Screen.Inch..., is value: Base) -> Self { + for type in types where Screen.Inch.current == type { + self.value = value + } + return self + } + + public func level(_ types: Screen.Level..., is value: Base) -> Self { + for type in types where Screen.Level.current == type { self.value = value } return self @@ -162,12 +177,6 @@ public enum Screen { } } } - - case inch(Inch) - case width(Width) - case height(Height) - - case level(Level) } extension Screen { @@ -183,15 +192,6 @@ extension Screen { public static var isFull: Bool { return Level.current == .full } - - public var isCurrent: Bool { - switch self { - case .width(let value): return Width.current == value - case .height(let value): return Height.current == value - case .inch(let value): return Inch.current == value - case .level(let value): return Level.current == value - } - } } extension Int: ScreenCompatible {}