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
public typealias ConstraintsConfiguration = (_ top: NSLayoutConstraint, _ left: NSLayoutConstraint, _ bottom: NSLayoutConstraint, _ right: NSLayoutConstraint) -> Void | |
extension UIView { | |
/** | |
Embeds a subview inside the current view and adds constraints to fit the subview in the whole view. An optional constraints configuration closure can be specified to do extra customization for the added constraints, or you can keep a reference for the added constraints in this closure. | |
- Parameter subview: The subview that will be added | |
- Parameter constraintsConfiguration: The constraint configuration that will be applied to the newly added constraints | |
*/ | |
public func addSubviewWithConstraints(_ subview: UIView, constraintsConfiguration: ConstraintsConfiguration? = nil) { | |
// Required to disable auto generation of constraints |
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 Optional { | |
/** | |
Unwraps a value or returns the default value provided if it's nil | |
- parameter defaultValue: The default value that will be returned if the original value is nil | |
*/ | |
func unwrap(defaultValue: Wrapped) -> Wrapped { | |
guard let self = self else { | |
// Make the app crash in debug but not in production |
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
post_install do |installer| | |
installer.pods_project.targets.each do |target| | |
if ['RxSwift', 'RxCocoa', 'RxAlamofire', 'RxTest', 'RxBlocking'].include? target.name | |
target.build_configurations.each do |config| | |
config.build_settings['SWIFT_VERSION'] = '3.3' | |
end | |
end | |
end | |
end |
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
class ListingView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
initView() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
initView() |
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
// Step 1 | |
guard let xibItems = Bundle.main.loadNibNamed("ListingView", owner: self, options: nil), let firstXibView = xibItems[0] as? UIView else { | |
fatalError("Xib is empty or first view is not a UIView") | |
} | |
// Step 2 | |
firstXibView.translatesAutoresizingMaskIntoConstraints = false | |
// Step 3 | |
let viewConstraints = [NSLayoutAttribute.top, NSLayoutAttribute.left, NSLayoutAttribute.bottom, NSLayoutAttribute.right].map { (attribute) -> NSLayoutConstraint in | |
return NSLayoutConstraint(item: firstXibView, attribute: attribute, relatedBy: .equal, toItem: self, attribute: attribute, multiplier: 1, constant: 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
class ListingView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
initView() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
initView() |
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 | |
import MSAutoView | |
class ListingView: MSAutoView { } |
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
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { | |
return cellSpacing | |
} |
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
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { | |
let target = targetContentOffset.pointee | |
//Current scroll distance is the distance between where the user tapped and the destination for the scrolling (If the velocity is high, this might be of big magnitude) | |
let currentScrollDistance = target.x - currentScrollOffset.x | |
//Make the value an integer between -1 and 1 (Because we don't want to scroll more than one item at a time) | |
let coefficent = Int(max(-1, min(currentScrollDistance/scrollThreshold, 1))) | |
let currentIndex = Int(round(currentScrollOffset.x/itemWidth)) | |
let adjacentItemIndex = currentIndex + coefficent | |
let adjacentItemIndexFloat = CGFloat(adjacentItemIndex) | |
let adjacentItemOffsetX = adjacentItemIndexFloat * (itemWidth(scrollView) + cellSpacing) |
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
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { | |
currentScrollOffset = scrollView.contentOffset | |
} |
NewerOlder