Skip to content

Instantly share code, notes, and snippets.

View roman-wb's full-sized avatar

Roman D roman-wb

  • Russia, Rostov-on-Don
View GitHub Profile
@roman-wb
roman-wb / MyView.swift
Last active December 6, 2018 09:00
IBDesignable for UIView (including borderColor, borderWidth, cornerRadius, Gradient)
import UIKit
@IBDesignable class MyView: UIView {
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}
@roman-wb
roman-wb / MyButton.swift
Last active February 4, 2019 16:25
IBDesignable for UIButton (including borderColor, borderWidth, cornerRadius, Gradient)
import UIKit
@IBDesignable class MyButton: UIButton {
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}
# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
name = x
email = x
[alias]
co = checkout
ci = commit
st = status
br = branch
@roman-wb
roman-wb / Settings.swift
Last active December 9, 2018 22:14
Singleton class for store boolean Settings in UserDefaults iOS (Swift)
import UIKit
class Settings {
static let shared = Settings()
private let manager = UserDefaults.standard
enum List: String {
case notify
case nightMode
@roman-wb
roman-wb / Database.swift
Last active December 9, 2018 22:29
Copy app bundle file (read-only) to app documents (read-write, database etc).
func copyDatabaseIfNeeded() {
let fileManager = FileManager.default
guard let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
let finalDatabaseUrl = documentsUrl.appendingPathComponent("sample.db")
do {
if !fileManager.fileExists(atPath: finalDatabaseURL.path) {
@roman-wb
roman-wb / ExtensionRussianPluralize.swift
Last active December 11, 2018 14:07
Swift russian pluralize numbers as extension for Int and Double
extension Int {
func pluralize(one: String, two: String, more: String) -> String {
let remainderOf10 = self % 10
let remainderOf100 = self % 100
if remainderOf10 == 1 && remainderOf10 != 11 {
return one
}
@roman-wb
roman-wb / ExtensionUIViewController.swift
Last active January 25, 2019 06:29
Extension for instance Storyboard one Controller
// Variant 1
extension UIViewController {
static func instance<T: UIViewController>() -> T? {
let name = String(describing: self)
let storyboard = UIStoryboard(name: name, bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: name)
return controller as? T
}
}
@roman-wb
roman-wb / MyLabel.swift
Created February 1, 2019 13:31
IBDesignable for UILabel (including kerning attributed)
import UIKit
@IBDesignable class MyLabel: UILabel {
@IBInspectable var kerning: Float {
get {
let string = text ?? ""
var range = NSMakeRange(0, string.count)
guard let kern = attributedText?.attribute(.kern, at: 0, effectiveRange: &range),
@roman-wb
roman-wb / ModalAnimationController.swift
Last active February 18, 2019 16:42
Modal Animation Controller with custom transition
import UIKit
class ModalAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
fatalError("Abstract method")
}
let cornerRadius: CGFloat = 20
let offset: CGFloat = 60
@roman-wb
roman-wb / MyUIButton.swift
Created March 1, 2019 08:11
iOS custom UIButton with roundedRect, shadow and highlight.
import UIKit
class MyUIButton: UIButton {
var highlightTitle = false
var highlightBackground = false
var highlightLayer = false
override open var isHighlighted: Bool {
didSet {