Skip to content

Instantly share code, notes, and snippets.

View SergLam's full-sized avatar
😊
Try to make your code better!

Serhii Liamtsev SergLam

😊
Try to make your code better!
View GitHub Profile
@SergLam
SergLam / BubbleTriangleView.swift
Created January 11, 2021 22:04
Bubble Triangle View in Swift for iOS
import UIKit
final class BubbleTriangleView: UIView {
private var viewBorderWidth: CGFloat = 3
private var radius: CGFloat = 15
private var viewFillColor: UIColor = .supAzure
private var viewBorderColor: UIColor = .white
@SergLam
SergLam / CountingLabel.swift
Created January 11, 2021 22:01
Animated counting UILabel for iOS in Swift
// Source - https://medium.com/@topLayoutGuide/swift-3-so-i-wanted-to-animate-a-label-14dd2b332ef9
//
// https://github.com/dataxpress/UICountingLabel/
//
import UIKit
enum CountingMethod {
case easeInOut
case easeIn
import UIKit
/// Represents a single `NSLayoutConstraint`
enum LayoutAnchor {
case constant(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
constant: CGFloat)
case relative(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
@SergLam
SergLam / CustomVC.swift
Created January 7, 2021 20:16
SwiftUI previews for UIKit
import UIKit
final class CustomVC: UIViewController {
private lazy var contentView: CustomView = CustomView()
// MARK: - Life cycle
deinit {
NotificationCenter.default.removeObserver(self)
}
@SergLam
SergLam / WordsFlexView.swift
Created December 10, 2020 16:32
Hashtags colored view sample implementation using UIStackViews
import UIKit
protocol WordsFlexViewDelegate: class {
func didSelectWord(word: String, intId: Int, phraseView: WordsFlexView)
}
class WordsFlexView: UIView {
enum WordsFlexViewType {
case selectable
@SergLam
SergLam / Animation.md
Created December 4, 2020 10:40 — forked from JeOam/Animation.md
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

@SergLam
SergLam / HitTestUIView.swift
Created November 16, 2020 16:14
Pass touches over view bounds
import UIKit
class HitTestUIView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if clipsToBounds || isHidden || alpha == 0 {
return nil
}
for subview in subviews.reversed() {
let subPoint = subview.convert(point, from: self)
@SergLam
SergLam / USAState.swift
Created November 2, 2020 12:23
USA States names + ISO 3166-2 codes
import Foundation
// https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations
// https://en.wikipedia.org/wiki/ISO_3166-2
// NOTE: - Last two symbols from ISO 3166-2 state code
enum USAState: Int, CaseIterable {
case alabama = 1
case alaska = 2
@SergLam
SergLam / Links.swift
Created September 17, 2020 15:02
Collection view - self sizing cells!!!!
@SergLam
SergLam / FileWebService.swift
Created September 14, 2020 06:25 — forked from boboboa32/FileWebService.swift
Moya file download
import Moya
import SwiftyJSON
enum FileWebService {
case download(url: String, fileName: String?)
var localLocation: URL {
switch self {
case .download(let url, let fileName):
let fileKey: String = url.MD5 // use url's md5 as local file name