mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-22 19:28:54 +10:00
add pickMarginIn to UIDevice for a better use case
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user