Skip to content

Instantly share code, notes, and snippets.

@raaowx
raaowx / UIViewController.swift
Last active March 2, 2023 16:54
Swift - UIKit - UIViewController
import UIKit
extension UIViewController {
/// Print through console the current view controllers hierarchy.
func printHierarchy() {
let log = { (str: String) in
print("*** *** *** *** *** *** *** *** ***")
print(str)
print("*** *** *** *** *** *** *** *** ***")
}
@raaowx
raaowx / UIColor.swift
Last active March 2, 2023 17:17
Swift - UIKit - UIColor
import UIKit
extension UIColor {
/// An object that stores color data and sometimes opacity.
///
/// This failable convenience init allows to create an `UIColor` from a hexadecimal `String`. Supported format examples:
/// - #FFF = UIExtendedSRGBColorSpace 1 1 1 1
/// - #FFF0 = UIExtendedSRGBColorSpace 1 1 1 0
/// - #FFFFFF = UIExtendedSRGBColorSpace 1 1 1 1
/// - #FFFFFF0 = UIExtendedSRGBColorSpace 1 1 1 0
@raaowx
raaowx / UILabel.swift
Last active March 2, 2023 16:56
Swift - UIKit - UILabel
import UIKit
extension UILabel {
/// The number of lines required by the containing text taking into account the font line height.
var lines: Int {
guard let text = self.text as? NSString else { return 0 }
let size = CGSize(width: self.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = text.boundingRect(
with: size,
options: .usesLineFragmentOrigin,