Skip to content

Instantly share code, notes, and snippets.

View Kharauzov's full-sized avatar
👨‍💻
Focusing

Serhii Kharauzov Kharauzov

👨‍💻
Focusing
  • Warsaw, Poland
View GitHub Profile
func setCardChildViewController(_ viewController: UIViewController, hostView: CardView) {
add(viewController)
hostView.addSubview(viewController.view)
hostView.backgroundColor = viewController.view.backgroundColor
viewController.view.frame = CGRect(origin: hostView.bounds.origin, size: CGSize(width: hostView.bounds.size.width, height: hostView.bounds.size.height - CardsHolderView.Constants.subviewBottomOffset))
}
func setTopChildViewController(_ viewController: UIViewController) {
add(viewController)
customView.topView.addSubview(viewController.view)
private func setChildViewControllers() {
let topViewController = ProfileShortInfoViewController()
view.backgroundColor = topViewController.view.backgroundColor
let card1ViewController = ProfileActivityViewController()
let card2ViewController = RecommendationsViewController()
setTopChildViewController(topViewController)
setCard1ChildViewController(card1ViewController)
setCard2ChildViewController(card2ViewController)
self.topViewController = topViewController
self.activityViewController = card1ViewController
// This view is a root view inside CardsHolderViewController
class CardsHolderView: UIView {
let topView = UIView()
let cardView1 = CardView()
let cardView2 = CardView()
///
/// some other code here
///
@Kharauzov
Kharauzov / .swift
Created February 27, 2020 16:00
Basic methods to work with child view controllers
func add(_ child: UIViewController, shouldAddView: Bool = false) {
addChild(child)
if shouldAddView {
view.addSubview(child.view)
}
child.didMove(toParent: self)
}
func remove(shouldRemoveView: Bool = false) {
guard parent != nil else {
struct ScreenSize {
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenMaxLength = max(ScreenSize.screenWidth, ScreenSize.screenHeight)
static let screenMinLength = min(ScreenSize.screenWidth, ScreenSize.screenHeight)
}
/// Type of device, based on screen size.
struct DeviceType {
import UIKit
class ProfileView: UIView {
// Some properties
var titleLabel: UILabel
var profileImageView: UIImageVew
var profileImageViewTopConstraint: NSLayoutConstraint
var titleLabelLeadingConstraint: NSLayoutConstraint
import Foundation
/// SB - screen based
/// Use `definedValue` to get value, depending on the screen of device.
struct SBValue<T> {
/// Corresponds to 4" screen
let iPhoneSE: T
/// Corresponds to 4.7" screen
let iPhone8: T
/// Corresponds to 5.5" screen
import UIKit
class ProfileView: UIView {
// Some properties
var titleLabel: UILabel
var profileImageView: UIImageVew
var profileImageViewTopConstraint: NSLayoutConstraint
var titleLabelLeadingConstraint: NSLayoutConstraint
@Kharauzov
Kharauzov / PHPhotoLibrary+PhotoAsset.swift
Last active November 25, 2024 18:33 — forked from ricardopereira/PHPhotoLibrary+PhotoAsset.swift
Updated version of extension, adopted to Swift 5. Added functional to save array of assets. Modify saving of one asset, making it universal for both images via UIImage and videos via URLs.
import Photos
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveAssets(_ assets: [Any], albumName: String, completion: @escaping ([PHAsset]?)->()) {
if let album = self.findAlbum(albumName: albumName) {
saveAssets(assets, album: album, completion: completion)
extension SwipingCollectionViewCell: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}