Skip to content

Instantly share code, notes, and snippets.

View cscouto's full-sized avatar
🎯
Focusing

Tiago Do Couto cscouto

🎯
Focusing
View GitHub Profile
@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 / ViewController.Swift
Last active February 6, 2025 10:12
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 / 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 / Array.m
Created February 17, 2018 02:49
OBJECTIVE-C - Invert Array
NSArray* reversedArray = [[startArray reverseObjectEnumerator] allObjects];
@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,