Skip to content

Instantly share code, notes, and snippets.

Code for life.

Nguyen Truong Ky nguyentruongky

Code for life.
Block or report user

Report or block nguyentruongky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
nguyentruongky / UITextFieldExtension.swift
Created May 15, 2019
UITextField extension functions
View UITextFieldExtension.swift
// UITextField.swift
// kLibrary
// Created by Ky Nguyen on 8/27/16.
// Copyright © 2016 Ky Nguyen. All rights reserved.
import UIKit
nguyentruongky / button_process_indicator.swift
Created May 6, 2019
Show indicator view inside UIButton
View button_process_indicator.swift
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
nguyentruongky / view_loading_indicator.swift
Created Apr 24, 2019
Add loading indicator with color, size to any views
View view_loading_indicator.swift
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
View long_press_gesture_recognizer.swift
class Animator {
var view = UIView()
lazy var dropZone = self.makeDropZone()
var dragImageView: UIImageView?
var startPoint =
var recognizer: UILongPressGestureRecognizer?
private func makeDropZone() -> UIView {
let dropZoneEdge = 250
let dropZoneMissingEdge: CGFloat = 50
View add_event_to_calendar.swift
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() }
View Basic_authorization.swift
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,
nguyentruongky / tab_controller_slide.swift
Created Nov 14, 2017
Slide animation in tab bar controller
View tab_controller_slide.swift
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 }
nguyentruongky / tab_controller_fading.swift
Created Nov 14, 2017
Fade animation in tab bar controller
View tab_controller_fading.swift
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 /
Last active Apr 24, 2017
Tips to save your time and make your code quality become better. This talk is presented in Swift Battle.

Make the Most of Your 24 Hours

Bitter Experience

I started iOS as a 2-year-experience .NET developer. The salary range for a junior iOS dev is a little bit lower than the amount for a 2-year-experience develop get. I wanted to make myself stronger, earn more experience. I had a misconception of working and learning. I thought, freelance projects will help me strengthen my knowledge and experience. So I tried to get as more as possible freelance projects. And my nightmare started from here.

I had no time to spend with my family, no time to work on personal improvement, no time to go out with friends, no time at all. All of my time was used up on my freelance work from coding new features, fixing bugs and much more. I was killing myself working odd hours and missing out on quality time with my family and friends.

I made a mess, uncountable technical debts, bugs, with the project. I was angry with everyone and myself. And the company project was affected. I brought more bugs there, dozens of stupid bug

nguyentruongky /
Last active Aug 21, 2019
Should I implement UI with Storyboard or by Programmatically?

Auto Layout with Storyboard and Programmatically

I started iOS development as a .NET developer. My first impression, Storyboard is really really interesting. 80% UI of my apps is built in Storyboard. I can't imagine how I can develop iOS without Storyboard.

There are many discussions about Auto Layout with Storyboard or Programmatically is better. But no one wins. Everyone has own reason and belief.

This post is my personal opinion. It's written by a developer can't live without Storyboard, and now he abandons it.

3 reasons why he changed to Auto Layout by programmatically.

Why do I abandon Storyboard?

You can’t perform that action at this time.