Skip to content

Instantly share code, notes, and snippets.

View vladimir-anisimov's full-sized avatar
🏠
Working from home

vladimir-anisimov

🏠
Working from home
  • Warsaw, Poland
View GitHub Profile
@vladimir-anisimov
vladimir-anisimov / SwipeableCell.swift
Created April 5, 2021 09:05
UICollectionViewCell with swipe support
import UIKit
class SwipeableCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var maxSwipeOffset = CGFloat(200)
private var pan: UIPanGestureRecognizer!
override init(frame: CGRect) {
super.init(frame: frame)
@vladimir-anisimov
vladimir-anisimov / UIReusableView + Reusable.swift
Last active April 6, 2021 11:40
Reuse identifier for reusable elements
import UIKit
protocol Reusable: class {
static var reuseIdentifier: String { get }
}
extension UICollectionViewCell: Reusable {
static var reuseIdentifier: String {
return self.description()
@vladimir-anisimov
vladimir-anisimov / MakeFile
Last active February 6, 2022 23:10
build framework Makefile
ios:
xcodebuild archive \
-scheme TweakFramework \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/TweakFramework.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
simulator:
import UIKit
extension UIButton {
func centerTextAndImage(spacing: CGFloat) {
let insetAmount = spacing / 2
let writingDirection = UIApplication.shared.userInterfaceLayoutDirection
let factor: CGFloat = writingDirection == .leftToRight ? 1 : -1
self.imageEdgeInsets = UIEdgeInsets(top: 0,
left: -insetAmount*factor,
bottom: 0,
@vladimir-anisimov
vladimir-anisimov / UIView + ColorOfPoint.swift
Created April 29, 2022 11:08
Color of point in UIView
extension UIView {
func colorOfPoint(point: CGPoint) -> UIColor {
let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
var pixelData: [UInt8] = [0, 0, 0, 0]
guard let context = CGContext(data: &pixelData,
width: 1,
height: 1,
bitsPerComponent: 8,
bytesPerRow: 4,
import UIKit
extension UIColor {
convenience init(hexString: String, alpha: CGFloat = 1) {
self.init(hex: UInt(hexString.dropFirst(),
radix: 16) ?? 0, alpha: alpha)
}
convenience init(hex: UInt, alpha: CGFloat = 1) {
self.init(red: .init((hex & 0xff0000) >> 16) / 255,
green: .init((hex & 0xff00 ) >> 8) / 255,
extension String {
func matches(_ regex: String) -> Bool {
return self.range(of: regex,
options: .regularExpression,
range: nil,
locale: nil) != nil
}
}
extension String {
var isBlank: Bool {
return self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
func replace(string:String, replacement:String) -> String {
return self.replacingOccurrences(of: string, with: replacement, options: NSString.CompareOptions.literal, range: nil)
}
func removeWhitespace() -> String {
return self.replace(string: " ", replacement: "")
extension UIColor {
var redValue: CGFloat{ return CIColor(color: self).red }
var greenValue: CGFloat{ return CIColor(color: self).green }
var blueValue: CGFloat{ return CIColor(color: self).blue }
var alphaValue: CGFloat{ return CIColor(color: self).alpha }
convenience init(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1) {
self.init(red: r / 255, green: g / 255, blue: b / 255, alpha: a)
}
}
extension TimeInterval {
static var second: TimeInterval {
return 1.0
}
static var minute: TimeInterval {
return second * 60.0
}
static var hour: TimeInterval {