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_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 }
@nguyentruongky
nguyentruongky / Gradient_border_button.md
Last active May 31, 2023 00:00
A library to create gradient border button

How to draw a gradient border button?

My Problem

Last week, my partner showed me his design for our application. Everything is great, easily implemented with some custom controls. But wait, something is not in my knowledge.

A button with gradient border. Never try it before. Up to now, I just created gradient background views 2 times in previous projects. Googled and found some good results.

@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 / Effectively_manage_your_time.md
Last active July 16, 2021 15:09
3 Tips on How to effectively manage your time

3 Tips on How to Effectively Manage Your Time

One of the luxuries of working as a freelancer is having the ability to create your own schedule, work when you want, and at your own pace. Some see it as a blessing and some see it as a curse. If you’re new to the fast-growing freelancer industry, this might be a tough adjustment. Especially if you’re coming from a strict 9-to-5 work schedule. We spoke to Freelance Developer, Ky Nguyen about his personal experience juggling work, his freelancer gigs, and his personal life. He’s highlighted a few noteworthy tips on how to manage your time as a freelancer and make your freelance career just that much more worthwhile.

Make the Most of Your 24 Hours

Have you ever wished you had more than 24 hours in a day? I sure have. There came a point in my life when I had a really hard time with time management and I wasn’t about to find a way to get out of this

// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
using namespace std;
struct Sach
{
string id;
string tenSach;
string tacGia;
@nguyentruongky
nguyentruongky / Auto_Layout_Programmatically.md
Last active August 21, 2019 11:10
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?

@nguyentruongky
nguyentruongky / Airbnb_home_screen.md
Last active May 24, 2019 15:09
A simple sample of Airbnb's home screen

Airbnb Home screen sample

You can see it anywhere. It's very popular in home screen, gallery screen. See how to do that.

  • Create new project. Remove ViewController.swift and the view controller in Main storyboard.
  • Add TableViewController to storyboard. Don't forget check Is Initial View Controller
  • Name the Table View Cell and Identifier HeaderCell. Set cell's height to 400.
  • Design your cell look like this
@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
@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)
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