Skip to content

Instantly share code, notes, and snippets.

@konnnn
konnnn / UISheetPresentationController.swift
Last active April 15, 2022 21:08
Present a ViewController on Half screen
// iOS 15 and above
func presentSecondViewController() {
guard let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController else { return }
secondViewController.providesPresentationContextTransitionStyle = true
secondViewController.definesPresentationContext = true
secondViewController.modalPresentationStyle = .formSheet // The presentation style for modal view controllers
secondViewController.isModalInPresentation = true // Cancels dismiss the viewController by swiping down
secondViewController.modalTransitionStyle = .coverVertical // The transition style to use when presenting the view controller
@konnnn
konnnn / AppInfo.swift
Last active February 22, 2021 20:30
App information such as app name, app version, etc.
// App information such as app name, app version, etc.
// AppInfo.swift
// Created by Evgeny Konkin on 23.02.2021.
//
import Foundation
struct AppInfo {
private static func dictionary(key string: String) -> String? {
@konnnn
konnnn / NavigationBar+ClearAndFont.swift
Last active February 15, 2021 18:38
Clear Navigation Bar bottom shadow, set clear color and translucent true
//
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
setupAppearance()
}
fileprivate func setupAppearance() {
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: UIBarMetrics.default)
@konnnn
konnnn / NSUserDefaults.swift
Last active October 17, 2020 23:20
Setting default values for NSUserDefaults
/*
UserDefaults (NSUserDefaults) is a go-to database for saving users' preferences over application behavior,
e.g., font size, sound disable/enable. So, most of the time, you want each of them to have a default value.
*/
// Basic approach
let userDefaults = UserDefaults.standard
// 1
@konnnn
konnnn / NavigationBar+CustomFont.swift
Last active February 15, 2021 18:29
Customize Navigation Bar Font and Color
// NavigationBar+Custom.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// navigation bar title
@konnnn
konnnn / UIButton+Border.swift
Created April 17, 2020 17:01
Adds a border to the UIButton
// Created by Evgeny Konkin on 17/04/2020.
import UIKit
enum BorderSide {
case top, bottom, left, right
}
extension UIButton {
@konnnn
konnnn / systemFont.swift
Last active February 22, 2023 01:07
UIFont extension for San Francisco system font style selection
extension UIFont {
/// San Francisco System Font
/// - Parameters:
/// - fontSize: Font size
/// - weight: Font weight (Optional, by default: weight is regular)
/// - design: Font design: default, rounded, monospaced, serif (Optional, by default: design is default)
/// - Returns: System font of your size, weight and design
static func systemFont(ofSize fontSize: CGFloat, weight: UIFont.Weight = .regular, design: UIFontDescriptor.SystemDesign = .default) -> UIFont {
// Will be SF Compact or standard SF in case of failure.
if let descriptor = UIFont.systemFont(ofSize: fontSize, weight: weight).fontDescriptor.withDesign(design) {
@konnnn
konnnn / playSound.swift
Last active March 6, 2020 20:33
Play Sound Function
// MARK: Play sound function
func playSound(fileName: String) {
guard let url = Bundle.main.url(forResource: fileName, withExtension: "mp3") else {
print("the sound file isn't founded")
return
}
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)
@konnnn
konnnn / layered-list.html
Last active December 21, 2019 22:11
Многоуровневый список (1, 2, 3... 1.1, 1.2... 1.1.1, 1.1.2) https://codepen.io/konnn/pen/MWYmKgb
<!DOCTYPE html>
<head>
<style>
ol {
list-style-type: none;
counter-reset: item;
}
li:before {
content: counters(item, '.', decimal) '. ';
counter-increment: item;
@konnnn
konnnn / reset.css
Created November 15, 2019 19:52 — forked from DavidWells/reset.css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0-modified | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,