Skip to content

Commit

Permalink
2.1.0 优化API设计
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed Oct 22, 2020
1 parent d0f7617 commit da2ccaa
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion AutoInch.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions AutoInch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down Expand Up @@ -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)";
Expand Down
24 changes: 12 additions & 12 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,31 @@ 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
```


```swift
// 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
)
```
Expand Down
25 changes: 12 additions & 13 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,31 @@ 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
```


```swift
// 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
)
```
Expand Down
40 changes: 20 additions & 20 deletions Sources/Screen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -162,12 +177,6 @@ public enum Screen {
}
}
}

case inch(Inch)
case width(Width)
case height(Height)

case level(Level)
}

extension Screen {
Expand All @@ -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 {}
Expand Down

0 comments on commit da2ccaa

Please sign in to comment.