Skip to content

Instantly share code, notes, and snippets.

@mbuff24
Created May 10, 2016 01:32
Show Gist options
  • Save mbuff24/cb4626c29d982057496ab220a5475caa to your computer and use it in GitHub Desktop.
Save mbuff24/cb4626c29d982057496ab220a5475caa to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
import QuartzCore
extension UIImage {
class func imageWithLabel(label: UILabel) -> UIImage {
UIGraphicsBeginImageContextWithOptions(label.bounds.size, false, 0.0)
label.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
}
let bicep = "💪"
let view = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 640))
view.backgroundColor = UIColor.whiteColor()
let label = UILabel(frame: CGRect(origin: CGPointZero, size: CGSize(width: 50, height: 50)))
label.text = bicep
let image = UIImage.imageWithLabel(label)
let imageView = UIImageView(image: image)
imageView.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let emitterLayer = CAEmitterLayer()
emitterLayer.emitterPosition = CGPoint(x: view.bounds.size.width / 2, y: view.bounds.origin.y)
emitterLayer.emitterZPosition = 10
emitterLayer.emitterSize = CGSize(width: view.bounds.size.width, height: 0)
emitterLayer.emitterShape = kCAEmitterLayerSphere
let emitterCell = CAEmitterCell()
emitterCell.scale = 1
emitterCell.scaleRange = 0.2
emitterCell.emissionRange = CGFloat(M_PI_2)
emitterCell.lifetime = 5.0
emitterCell.birthRate = 5
emitterCell.velocity = 200
emitterCell.velocityRange = 50
emitterCell.yAcceleration = 250
emitterCell.contents = image.CGImage
emitterLayer.emitterCells = [emitterCell]
view.layer.addSublayer(emitterLayer)
XCPlaygroundPage.currentPage.liveView = view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment