This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |