Skip to content

Instantly share code, notes, and snippets.

View gromwel's full-sized avatar

Pavel gromwel

View GitHub Profile
@gromwel
gromwel / ContentView.swift
Created January 29, 2023 20:46
Прилипающие заголовки (есть проблема с перфомансом)
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView {
contents
}
.navigationTitle("title")
.useStickyHeaders()
@gromwel
gromwel / ContentView.swift
Last active January 29, 2023 20:33
Пагинированные горизонтальные карточки
import SwiftUI
struct ContentView: View {
var body: some View {
GeneralPagerView()
}
}
struct GeneralPagerView: View {
// актуальная страница
@gromwel
gromwel / custom_alignment.swift
Created August 7, 2022 21:08
Custom Vertical Horizontal alignment
struct ContentView: View {
var body: some View {
VStack(spacing: 40) {
HStack(alignment: .midLeftAndRight) {
VStack {
Text("Left 1")
Text("Left 2")
.alignmentGuide(.midLeftAndRight) {
$0[.bottom] / 2
}
@gromwel
gromwel / example.swift
Created August 3, 2022 15:21
SwiftUI Gradient Animation
struct ContentView: View {
@State private var animateGradient = false
var body: some View {
ZStack {
LinearGradient(
colors: [.red, .purple],
startPoint: animateGradient ? .topLeading : .bottomLeading,
endPoint: animateGradient ? .bottomTrailing : .topTrailing
)
@gromwel
gromwel / tags_view.swift
Created July 7, 2022 13:40
Вьюха с расстановкой контента построчно с переносами
import SwiftUI
import Combine
extension Int {
static func random() -> Int {
let lenght = Int.random(in: 1...15)
return Array(0...lenght).reduce(into: 0) { result, x in
let random = Array(0...9).randomElement() ?? 0
result *= 10
result += random
@gromwel
gromwel / SingleViewAccessory.swift
Created April 12, 2021 11:11
Single view accessory view
final class SingleViewAccessory: UIView {
// MARK: - Контент
private let contentView: UIView
// MARK: - Инициализация
init(content: UIView, background: UIColor = .clear) {
// Контент
@gromwel
gromwel / KeychainManager.swift
Created April 4, 2021 22:18
Keychain manager set get delete update
final class KeychainManager {
static func set(data: Data, service: String, account: String) {
// Данные для сохранения
let item = [
kSecClass: kSecClassGenericPassword,
kSecValueData: data,
kSecAttrService: service,
kSecAttrAccount: account,
] as CFDictionary
@gromwel
gromwel / Example.swift
Last active April 4, 2021 02:42
Custom navigation controller push pop transition animation
final class VC1: UIViewController {
private lazy var gr = UITapGestureRecognizer(target: self, action: #selector(self.tap))
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .systemPink
self.view.addGestureRecognizer(self.gr)
self.navigationController?.delegate = self
}
@gromwel
gromwel / ViewController.swift
Created March 22, 2021 22:18
Interactive Popup View
class ViewController: UIViewController {
// MARK: - Сабвью
private lazy var popup: UIView = {
let view = UIView()
view.backgroundColor = .systemIndigo
view.frame.size.height = self.state == .open ? 400.0 : 50.0
return view
}()
@gromwel
gromwel / UIColor+ContrastTextColor.swift
Created March 22, 2021 15:00
Contrast foreground text color
import UIKit
extension UIColor {
static func contrastTextColor(with background: UIColor) -> UIColor {
let darkText = UIColor.dark
let lightText = UIColor.white
return background.contrastRatio(with: darkText) > background.contrastRatio(with: lightText) ? darkText : lightText
}