Skip to content

Instantly share code, notes, and snippets.

View nguyentruongky's full-sized avatar
💻
Code for life.

Ky Nguyen nguyentruongky

💻
Code for life.
View GitHub Profile
@nguyentruongky
nguyentruongky / tab_controller_fading.swift
Created November 14, 2017 10:56
Fade animation in tab bar controller
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
animateFading(fromController: selectedViewController, toController: viewController)
return true
}
func animateFading(fromController: UIViewController?, toController: UIViewController?) {
if fromController == nil || toController == fromController { return }
guard let selectView = (selectedViewController as? UINavigationController)?.viewControllers.first?.view,
let newView = (toController as? UINavigationController)?.viewControllers.first?.view else { return }
@nguyentruongky
nguyentruongky / tab_controller_slide.swift
Created November 14, 2017 10:58
Slide animation in tab bar controller
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
animateSliding(fromController: selectedViewController, toController: viewController)
return false
}
func animateSliding(fromController: UIViewController?, toController: UIViewController?) {
guard let fromController = fromController, let toController = toController else { return }
guard let fromIndex = viewControllers?.index(of: fromController),
let toIndex = viewControllers?.index(of: toController) else { return }
let userName = "myUsername"
let password = "myPassword"
let authString = userName + ":" + password
let credentialData = authString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64Credentials = credentialData.base64EncodedStringWithOptions([])
let headers = ["Authorization": "Basic " + base64Credentials]
let url = URL(string: api)!
Alamofire.request(url, method: .post,
parameters: params,
struct ogeSystemCalendar {
let eventStore = EKEventStore()
func addEvent(title: String, startDate: Date,
endDate: Date, notes: String?) {
eventStore.requestAccess(to: .event) { (granted, error) in
if granted == false {
DispatchQueue.main.async {
self.tellNoPermission() }
return
class Animator {
var view = UIView()
lazy var dropZone = self.makeDropZone()
var dragImageView: UIImageView?
var startPoint = CGPoint.zero
var recognizer: UILongPressGestureRecognizer?
private func makeDropZone() -> UIView {
let dropZoneEdge = 250
let dropZoneMissingEdge: CGFloat = 50
@nguyentruongky
nguyentruongky / view_loading_indicator.swift
Created April 24, 2019 10:44
Add loading indicator with color, size to any views
extension UIView {
static let loadingViewTag = 1938123987
func showLoading(style: UIActivityIndicatorView.Style = .gray, color: UIColor? = nil, scale: CGFloat = 1) {
var loading = viewWithTag(UIView.loadingViewTag) as? UIActivityIndicatorView
if loading == nil {
loading = UIActivityIndicatorView(style: style)
}
loading?.scale(value: scale)
if let color = color {
loading?.color = color
@nguyentruongky
nguyentruongky / button_process_indicator.swift
Created May 6, 2019 02:56
Show indicator view inside UIButton
func setProcess(visible: Bool,
style: UIActivityIndicatorView.Style = .white) {
if visible {
titleLabel?.layer.opacity = 0
isEnabled = false
let indicator = UIActivityIndicatorView(style: style)
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.tag = 12398137
indicator.startAnimating()
addSubview(indicator)
@nguyentruongky
nguyentruongky / UITextFieldExtension.swift
Created May 15, 2019 09:02
UITextField extension functions
//
// UITextField.swift
// kLibrary
//
// Created by Ky Nguyen on 8/27/16.
// Copyright © 2016 Ky Nguyen. All rights reserved.
//
import UIKit
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
using namespace std;
struct Sach
{
string id;
string tenSach;
string tacGia;