Skip to content

Instantly share code, notes, and snippets.

@TheAdamBorek
Last active April 3, 2017 06:33
Show Gist options
  • Select an option

  • Save TheAdamBorek/404ec87069a0feb58651b3ef64ecc89e to your computer and use it in GitHub Desktop.

Select an option

Save TheAdamBorek/404ec87069a0feb58651b3ef64ecc89e to your computer and use it in GitHub Desktop.

Revisions

  1. TheAdamBorek revised this gist Apr 3, 2017. 2 changed files with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions ScreenSizes.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    enum ScreenSizes {
    static let threePointFiveInchesPhoneFrame = CGRect(x: 0, y: 0, width: 320, height: 480)
    static let fourInchesPhoneFrame = CGRect(x: 0, y: 0, width: 320, height: 568)
    static let fourPointSevenInchesPhoneFrame = CGRect(x: 0, y: 0, width: 375, height: 667)
    static let iPadPortrait = CGRect(x: 0, y: 0, width: 768, height: 1024)
    static let iPadLandscape = CGRect(x: 0, y: 0, width: 1024, height: 768)
    }
    File renamed without changes.
  2. TheAdamBorek created this gist Apr 3, 2017.
    29 changes: 29 additions & 0 deletions snapshot_multipleScreens.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    class SnapshotTestCase: FBSnapshotTestCase {

    private let frames: [String : CGRect] = [
    "iPadPortraitFrame": ScreenSizes.iPadPortrait,
    "iPadLandscapeFrame": ScreenSizes.iPadLandscape,
    "threePointFivePhoneFrame": ScreenSizes.threePointFiveInchesPhoneFrame,
    "fourInchesPhoneFrame": ScreenSizes.fourInchesPhoneFrame,
    "fourPointSevenInchesPhoneFrame": ScreenSizes.fourPointSevenInchesPhoneFrame
    ]

    override func getReferenceImageDirectory(withDefault dir: String!) -> String! {
    return snapshotReferenceImageDirectory
    }

    func verifyForScreens(view: UIView, file: StaticString = #file, line: UInt = #line) {
    for (identifier, frame) in frames {
    verify(view: view, frame: frame, identifier: identifier, file: file, line: line)
    }
    }

    func verify(view: UIView, frame: CGRect? = nil, identifier: String = "", file: StaticString = #file, line: UInt = #line) {
    if let frame = frame {
    view.frame = frame
    }
    view.layoutIfNeeded()
    FBSnapshotVerifyView(view, identifier: identifier, file: file, line: line)
    FBSnapshotVerifyLayer(view.layer, identifier: identifier, file: file, line: line)
    }
    }