Skip to content

Instantly share code, notes, and snippets.

View cscouto's full-sized avatar
🎯
Focusing

Tiago Henrique Do Couto cscouto

🎯
Focusing
  • Couto Code
  • Charlotte, NC
View GitHub Profile
@cscouto
cscouto / UIScrollView+ScrollMoves.swift
Last active February 17, 2018 03:01
SWIFT - Scrolling to bottom, top and to any view
import UIKit
extension UIScrollView {
func scrollToView(view:UIView, animated: Bool, navigationHeight: CGFloat?) {
let childStartPoint = view.frame.origin
let height = (navigationHeight ?? 0) * 2 + 16
self.scrollRectToVisible(
CGRect(x: 0,
y: childStartPoint.y - height,
width: 1,
@cscouto
cscouto / Array.m
Created February 17, 2018 02:49
OBJECTIVE-C - Invert Array
NSArray* reversedArray = [[startArray reverseObjectEnumerator] allObjects];
@cscouto
cscouto / UIColor-Hex.swift
Created February 18, 2018 08:20
SWIFT - Getting color from hex value
extension UIColor {
convenience init(hex: String) {
let scanner = Scanner(string: hex)
scanner.scanLocation = 0
var rgbValue: UInt64 = 0
scanner.scanHexInt64(&rgbValue)
let r = (rgbValue & 0xff0000) >> 16
@cscouto
cscouto / ViewController.Swift
Last active March 19, 2024 15:05
SWIFT - Observe contentSize fro the tableView
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var heightTableView: NSLayoutConstraint!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.addObserver(self,
forKeyPath: "contentSize",
options: .new,
context: nil)
@cscouto
cscouto / InterctiveLabel.Swift
Created March 16, 2018 19:32
SWIFT - Copying with UIMenuController from a UILabel
import UIKit
class InterctiveLabel: UILabel {
override var canBecomeFirstResponder: Bool {
return true
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
self.backgroundColor = UIColor(hex: "EEEEEE")
@cscouto
cscouto / MessageVC.Swift
Created March 16, 2018 19:36
SWIFT - Moving UITextField with the keyboard
import UIKit
class MessageVC: UIViewController {
@IBOutlet weak var textViewMessage: UITextView!
@IBOutlet weak var heightMessage: NSLayoutConstraint!
@IBOutlet var viewMessage: UIView! // the view that will be attached to the keyboard
var messageVM: MessageViewModel!
let MESSAGE_INITIAL_SIZE: CGFloat = 44
@cscouto
cscouto / CsvMapper.swift
Created March 25, 2018 17:15
SWIFT - CSV Mappper
//
// CsvMapper.swift
//
// Created by Tiago Do Couto on 3/25/18.
// Copyright © 2018 CoutoCode. All rights reserved.
//
import Foundation
open class CsvMapper {
@cscouto
cscouto / SquareLayout.kt
Created April 9, 2018 23:26
KOTLIN - Class to make a squared size item for you recyclerview grid layout
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.widget.RelativeLayout
/**
* Created by docouto on 4/9/18.
*/
@cscouto
cscouto / RecyclerViewTouchListener.kt
Created April 17, 2018 19:26
KOTLIN - Class to implement RecyclerView Click and Longclick
/*
* Copyright (c) 2018. Couto Code
*/
package com.coutocode.allgifts.Utils
/**
* Created by docouto on 4/17/18.
*/
@cscouto
cscouto / Image+Gif.Swift
Created May 9, 2018 23:35
SWIFT - Image gift loader
import UIKit
import ImageIO
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true