Skip to content

Instantly share code, notes, and snippets.

View heitara's full-sized avatar
💻
Swift & SwiftUI

Emil Atanasov heitara

💻
Swift & SwiftUI
View GitHub Profile
@heitara
heitara / record_video_stream
Last active August 5, 2016 07:05
Record video using ffmpeg
@echo off
rem batch file which starts video recording
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
rem echo %MyDate%
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
set time=%MyDate:~8,2%-%MyDate:~10,2%
set filename=%today%_%time%.mp4
echo %today%
@heitara
heitara / GridLayout.swift
Created April 30, 2018 14:59 — forked from smswz/GridLayout.swift
A simple custom grid UICollectionViewLayout
// MIT License
//
// Copyright (c) 2016 stable|kernel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@heitara
heitara / UIShowHideTextField_iOS12.swift
Created September 27, 2019 10:20
Password Text Field on iOS 12 with an icon on the right to reveal the password
class UIShowHideTextField: UnderlinedTextField {
let rightButton = UIButton(type: .custom)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
required override init(frame: CGRect) {
@heitara
heitara / UIShowHideTextField_iOS13.swift
Created September 27, 2019 10:23
Password Text Field on iOS 13+ with an icon on the right to reveal the password
class UIShowHideTextField: UnderlinedTextField {
let rightButton = UIButton(type: .custom)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
required override init(frame: CGRect) {
@heitara
heitara / swift_swipe_detect.swift
Created October 17, 2019 10:21
Swift Swipe Guester detector. Detect all four swipe directions. Swift 4
//more info on https://stackoverflow.com/questions/24215117/how-to-recognize-swipe-in-all-4-directions
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
@heitara
heitara / UIDevice+Extensions.swift
Created October 28, 2019 08:20
Distinguish different iPhones based on the device screen height.
//
// UIDevice+Extensions.swift
// tenbet
//
// Created by Emil Atanasov on 28.10.19.
// Copyright © 2019. All rights reserved.
//
//based on https://stackoverflow.com/questions/46192280/detect-if-the-device-is-iphone-x/47067296
@heitara
heitara / BadgeContainer.swift
Created February 2, 2020 14:09
Clean Red Badge implementation in Swift
// Created by © 2020 SwiftEverywhere. Can be used free of charge.
import UIKit
//protocol
protocol BadgeContainer: class {
var timer: Timer? { get set }
var badgeView: UIView? { get set }
var label: UILabel? { get set }
func showBadge(blink: Bool, text: String?)
func hideBadge()
}
@heitara
heitara / BadgeView.swift
Last active February 7, 2020 18:00
Add a Badge View with a Label
// Created by © 2020 SwiftEverywhere. Can be used free of charge.
import UIKit
//protocol
protocol BadgeContainer: class {
var badgeView: UIView? { get set }
var badgeLabel: UILabel? { get set }
func showBadge(blink: Bool, text: String?)
func hideBadge()
}
//default protocol implementation
@heitara
heitara / BadgeViewUsage.swift
Created February 10, 2020 22:23
Use BadgeContainer Protocol
//custom class
//Don't forget to assigne that custom class to your UIButton views in the storyboard file
class BadgeButton: UIButton, BadgeContainer {
var badgeTimer: Timer?
var badgeView: UIView?
var badgeLabel: UILabel?
}
//here is how to use it in simple view controller
class MyViewController: UIViewController {
@heitara
heitara / ImageMagick.Watermark.bat
Created May 3, 2020 07:55
Image Magick resize and manipulate files on Windows
REM add watermark to all JPG images in the same folder
REM resize all JPG images in the same folder
REM put the result in different folder
SET IMAGE_MAGICK="C:\Program Files\ImageMagick-7.0.10-Q16\magick.exe"
SET SIZE=700x700
mkdir watermark
mkdir resize
for /F "usebackq delims=" %%i in (`dir /a:-d /b %foldername%\*.jpg`) do %IMAGE_MAGICK% %%i ( watermark.png ) -gravity center -composite watermark\%%i