Last active
August 29, 2015 14:24
-
-
Save danzimm/ef6dbe31c6ff1dfd50c0 to your computer and use it in GitHub Desktop.
PlaygroundFun
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
func +(a: NSAttributedString, b: NSAttributedString) -> NSAttributedString { | |
let muty = NSMutableAttributedString(attributedString: a) | |
muty.appendAttributedString(b) | |
return muty | |
} | |
extension String: CustomPlaygroundQuickLookable { | |
public func customPlaygroundQuickLook() -> PlaygroundQuickLook { | |
let colors: [UIColor] = [ | |
.redColor(), .orangeColor(), .yellowColor(), | |
.greenColor(), .blueColor(), UIColor(red: 75.0/255.0, green: 0.0, blue: 130.0/255.0, alpha: 1.0), | |
.purpleColor() | |
] | |
let font: UIFont | |
let fontSize: CGFloat = 37.0 | |
if #available(iOS 8.2, *) { | |
font = UIFont.systemFontOfSize(fontSize, weight: UIFontWeightUltraLight) | |
} else { | |
font = UIFont.systemFontOfSize(fontSize) | |
} | |
let meow = self.characters.enumerate().map({ (i: Int, c: Character) in (colors[i % colors.count], c) }) | |
return PlaygroundQuickLook.AttributedString( | |
meow.reduce(NSAttributedString()) { (accum: NSAttributedString, t: (UIColor, Character)) in | |
accum + NSAttributedString(string: String(t.1), attributes: [ | |
NSForegroundColorAttributeName : t.0, | |
NSFontAttributeName : font | |
]) | |
} | |
) | |
} | |
} | |
"whoaoaoaoaoaoaoaoaoaoaoaoaoa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made with @JohnRHeaton