Skip to content

Instantly share code, notes, and snippets.

View alexbaramilis's full-sized avatar

Alexandros Baramilis alexbaramilis

View GitHub Profile
@alexbaramilis
alexbaramilis / TappableButtonInPlaygroundWithRxCocoa.swift
Created April 1, 2019 13:27
Playground with tappable button bound with RxCocoa
import UIKit
import PlaygroundSupport
import RxSwift
import RxCocoa
let signUpButton = UIButton()
signUpButton.setTitle("Tap me!", for: .normal)
signUpButton.sizeToFit()
let didTapSignUp = PublishSubject<Void>()
@alexbaramilis
alexbaramilis / String+indicesOfNumbers.swift
Last active April 16, 2019 15:55
Swift String Extension for finding the indices of all the numbers in a string.
import Foundation
extension String {
/// Returns the indices of all the numbers in the string.
///
/// If a number is directly preceded by a dot/comma, the index of the dot/comma
/// will also be returned.
/// This accounts for potential numbers with decimal or thousands separators.
var indicesOfNumbers: [Int] {
var indices = [Int]()
@alexbaramilis
alexbaramilis / UILabel+setAttributedTextWithSubscripts.swift
Last active April 16, 2019 15:55
Swift UILabel Extension for setting attributedText with specified character indices in subscript.
import UIKit
extension UILabel {
/// Sets the attributedText property of UILabel with an attributed string
/// that displays the characters of the text at the given indices in subscript.
func setAttributedTextWithSubscripts(text: String, indicesOfSubscripts: [Int]) {
let font = self.font!
let subscriptFont = font.withSize(font.pointSize * 0.7)
let subscriptOffset = -font.pointSize * 0.3
let attributedString = NSMutableAttributedString(string: text,