This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 3 | |
extension Array { | |
func filterDuplicates(includeElement: @escaping (_ lhs: Element, _ rhs: Element) -> Bool) -> [Element] { | |
var results = [Element]() | |
forEach { (element) in | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 3 | |
func setupBeaconRegions() { | |
// Use the .filterDuplicates function on an array of beacons to create a new array of only unique UUID's | |
let beaconRegions: [iBeaconItem] = iBeacons.filterDuplicates { $0.uuid == $1.uuid && $0.uuid == $1.uuid } | |
// Iterate through new array that only contains unique UUIDs and start ranging those | |
for beacon in beaconRegions { | |
startRangingBeacon(beacon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class SASwitch: UIView { | |
var backgroundView: UIView! | |
var beforeButton: UIButton! | |
var afterButton: UIButton! | |
var buttonWindow: UIView! | |
var beforeLabel: UILabel! | |
var afterLabel: UILabel! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
@IBDesignable class BMSegmentedControl: UIControl { | |
private var labels = [UILabel]() | |
var thumbView = UIView() | |
var items: [String] = ["BEFORE", "NEITHER", "AFTER"] { | |
didSet { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class BMSliderControl: UIControl { | |
var minimumValue: Double = 0.0 { | |
didSet { | |
updateLayerFrames() | |
} | |
} | |
OlderNewer