Skip to content

Instantly share code, notes, and snippets.

View romanmiller's full-sized avatar

Roman Stoliarchuk romanmiller

  • Lviv,Ukraine
View GitHub Profile
@PaulTaykalo
PaulTaykalo / mutable.swift
Created November 10, 2017 14:33
Mutable struct via block in swift
protocol Updateable {
func updated(block: (inout Self) -> ()) -> Self
}
extension Updateable {
func updated(block: (inout Self) -> ()) -> Self {
var item = self
block(&item)
return item
}
class Logger {
static var defaultLogger = Logger()
func log(_ message: String) {
print(message)
}
}
@romanmiller
romanmiller / UIImage+CGSize+Extensions
Last active July 3, 2021 19:05
Compress image size (Swift)
extension CGSize {
// get scale of image size with max dimention
public func scale(max: CGFloat) -> CGFloat {
if width > height{
if width > max {
return max / width
}
} else {
if height > max {
return max / height
@ilyapuchka
ilyapuchka / StickyLayout.swift
Last active February 25, 2024 18:43
Really sticky collection view layout
// The issue with sectionHeadersPinToVisibleBounds and sectionFootersPinToVisibleBounds is that they do not pin
// first header and last footer when bouncing. This layout subclass fixes that.
class StickyLayout: UICollectionViewFlowLayout {
override init() {
super.init()
self.sectionFootersPinToVisibleBounds = true
self.sectionHeadersPinToVisibleBounds = true
}
@romanmiller
romanmiller / UIButton + SpringAnimation
Last active March 18, 2017 10:04
Spring animation for UIButton (can use in extension for UIButton or for your custom button class) (Swift)
// from: size that button start animated; duration: time for animation;
func animateSpring(from: CGFloat,duration: TimeInterval) {
let scale = from / self.bounds.height
self.transform = CGAffineTransform(scaleX: scale, y: scale)
UIView.animate(withDuration: duration,
delay: 0,
usingSpringWithDamping: 0.6,
initialSpringVelocity: 0.4,