Skip to content

Instantly share code, notes, and snippets.

@Denismih
Denismih / setBottomBorder.swift
Last active August 21, 2018 13:35
[setBottomBorder to UITextField] #ios #UI #UITextField
extension UITextField {
func setBottomBorder() {
self.borderStyle = .none
self.layer.backgroundColor = UIColor.white.cgColor
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.gray.cgColor
self.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
self.layer.shadowOpacity = 1.0
self.layer.shadowRadius = 0.0
@Denismih
Denismih / circle.swift
Last active August 21, 2018 13:34
circle around the button #UI
// the circle around the play button
playButton.layer.cornerRadius = playButton.frame.size.height / 2.0
playButton.layer.borderWidth = 2.0
playButton.layer.borderColor = UIColor.white.cgColor
@Denismih
Denismih / string.swift
Created November 15, 2018 12:39
string slice
extension String {
func slice(from: String, to: String) -> String? {
return (range(of: from)?.upperBound).flatMap { substringFrom in
(range(of: to, range: substringFrom..<endIndex)?.lowerBound).map { substringTo in
String(self[substringFrom..<substringTo])
}
}
}
@Denismih
Denismih / push.swift
Created December 7, 2018 09:27
push from bottom
// push view controller but animate modally
let storyBoard: UIStoryboard = UIStoryboard(name: "myStoryBoard", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "myViewControllerIdentifier") as! MyViewController
let navigationController = self.navigationController
vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: vc, action: #selector(vc.closeView))
vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: vc, action: nil)
@Denismih
Denismih / AnimatedTabBarController.swift
Created December 14, 2018 13:54
AnimatedTabBarController
class AnimatedTabBarController: UITabBarController {
private var bounceAnimation: CAKeyframeAnimation = {
let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
bounceAnimation.values = [1.0, 1.4, 0.9, 1.02, 1.0]
bounceAnimation.duration = TimeInterval(0.3)
bounceAnimation.calculationMode = CAAnimationCalculationMode.cubic
return bounceAnimation
}()
@Denismih
Denismih / combining-git-repositories.md
Created January 9, 2019 13:58 — forked from msrose/combining-git-repositories.md
How to combine two git repositories.

Combining two git repositories

Use case: You have repository A with remote location rA, and repository B (which may or may not have remote location rB). You want to do one of two things:

  • preserve all commits of both repositories, but replace everything from A with the contents of B, and use rA as your remote location
  • actually combine the two repositories, as if they are two branches that you want to merge, using rA as the remote location

NB: Check out git subtree/git submodule and this Stack Overflow question before going through the steps below. This gist is just a record of how I solved this problem on my own one day.

Before starting, make sure your local and remote repositories are up-to-date with all changes you need. The following steps use the general idea of changing the remote origin and renaming the local master branch of one of the repos in order to combine the two master branches.

@Denismih
Denismih / ImageMessage.swift
Created January 24, 2019 14:43 — forked from rinat-enikeev/ImageMessage.swift
Chatto ImageMessage
// MARK: - ImageMessageModel
import Chatto
import ChattoAdditions
protocol ImageMessageModelProtocol: PhotoMessageModelProtocol {
var url: URL? { get set }
}
public class ImageMessageModel: PhotoMessageModel<MessageModel>, ImageMessageModelProtocol {
func convertVideo(phAsset : PHAsset){
PHImageManager.default().requestAVAsset(forVideo: phAsset, options: PHVideoRequestOptions(), resultHandler: { (asset, audioMix, info) -> Void in
if let asset = asset as? AVURLAsset {
do {
let videoData = try Data.init(contentsOf: asset.url)
print(asset.url)
self.orginalVideo = asset.url
print("File size before compression: \(Double(videoData.count / 1048576)) mb")
let compressedURL = NSURL.fileURL(withPath: NSTemporaryDirectory() + NSUUID().uuidString + ".MP4")
@Denismih
Denismih / AttachmentHandler.swift
Created January 29, 2019 13:42 — forked from deepakraj27/AttachmentHandler.swift
Access Camera, Photo Library, Video and File from User device using Swift 4
//
// AttachmentHandler.swift
// AttachmentHandler
//
// Created by Deepak on 25/01/18.
// Copyright © 2018 Deepak. All rights reserved.
//
import Foundation
import UIKit
import MobileCoreServices
func mimeTypeForPath(path: String) -> String {
let url = NSURL(fileURLWithPath: path)
let pathExtension = url.pathExtension
if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() {
if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
return mimetype as String
}