add pickMarginIn to UIDevice for a better use case

This commit is contained in:
nixzhu
2015-05-14 20:02:44 +08:00
parent 0ce40de7c3
commit ed9af48558
2 changed files with 24 additions and 12 deletions
+1 -10
View File
@@ -99,16 +99,7 @@ class YepConfig {
struct SocialWorkGithub {
struct Repo {
static let leftEdgeInset: CGFloat = {
switch UIDevice.screenWidthModel {
case .Classic:
return 20
case .Bigger:
return 40
case .BiggerPlus:
return 40
}
}()
static let leftEdgeInset = UIDevice.pickMarginIn([20, 40, 40])
static let rightEdgeInset = leftEdgeInset
}
}
+23 -2
View File
@@ -10,10 +10,16 @@ import UIKit
extension UIDevice {
enum ScreenWidthModel {
case Classic
enum ScreenWidthModel: Int {
case Classic = 0
case Bigger
case BiggerPlus
static var caseCount: Int {
var max: Int = 0
while let _ = self(rawValue: ++max) {}
return max
}
}
static let screenWidthModel: ScreenWidthModel = {
@@ -33,4 +39,19 @@ extension UIDevice {
return .Bigger // Default
}()
class func pickMarginIn(margins: [CGFloat]) -> CGFloat {
if margins.count < ScreenWidthModel.caseCount {
println("Warning: NOT enough margins")
if margins.count > 0 {
return margins[0]
} else {
return 0
}
}
return margins[screenWidthModel.rawValue]
}
}