Skip to content

Instantly share code, notes, and snippets.

@danzimm
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzimm/ef6dbe31c6ff1dfd50c0 to your computer and use it in GitHub Desktop.
Save danzimm/ef6dbe31c6ff1dfd50c0 to your computer and use it in GitHub Desktop.
PlaygroundFun
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"
@danzimm
Copy link
Author

danzimm commented Jul 5, 2015

Made with @JohnRHeaton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment