Skip to content

Instantly share code, notes, and snippets.

View SAllen0400's full-sized avatar

Sean Allen SAllen0400

View GitHub Profile
@SAllen0400
SAllen0400 / basicTernaryOperator.swift
Last active January 1, 2017 04:13
Basic Ternary Operator
// Bad way using if statement
func showMyView(bool: Bool) {
if bool == true {
UIView.animate(withDuration: 0.33, animations: {
self.myView.alpha = 1.0
})
} else {
UIView.animate(withDuration: 0.33, animations: {
self.myView.alpha = 0.0
@SAllen0400
SAllen0400 / progressBarAnimation.swift
Last active September 1, 2017 19:26
Animating Progress Bar
extension UIProgressView {
func animate(duration: Double) {
setProgress(0.01, animated: true)
UIView.animate(withDuration: duration, delay: 0.0, options: .curveLinear, animations: {
self.setProgress(1.0, animated: true)
}, completion: nil)
}
@SAllen0400
SAllen0400 / usingScreenSizeStruct.swift
Created December 25, 2016 21:23
Using Screen Size Struct
if DeviceTypes.iPhone5 || DeviceTypes.iPhone7Zoomed {
// Do any iPhone 5 (or iPhone7 Zoomed mode) specific code here
}
if DeviceTypes.iPhone7PlusStandard {
// Do any iPhone 7 Plus specific code here
}
@SAllen0400
SAllen0400 / screenSizeStructs.swift
Created December 25, 2016 21:15
Structs for Screen Sizes
struct ScreenSize {
static let SCREEN_WIDTH = UIScreen.main.bounds.size.width
static let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}
struct DeviceTypes {
static let iPhone4 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
static let iPhone5 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0