2013-04-01 14 views
9

vorrei utilizzare built-in caratteri emoji (in particolare, molte delle faccine, ad esempio \ue415) in un UILabel ma vorrei che l'emoji per essere resi in scala di grigi.Fai simboli emoji in scala di grigi in UILabel

I di Apple voglia loro di rimanere caratteri nella UILabel (testo normale o attribuito va bene). io non sto cercando una soluzione di immagine ibrido/string (che ho già).

qualcuno sa come eseguire questa operazione?

+0

Hai mai trovato una soluzione per questo? –

+0

@AlexBeals sfortunatamente no. – DrewInTheMountains

risposta

0

So che hai detto che non stai cercando un "ibrido im soluzione per età ", ma ho seguito questo drago per un po 'e il risultato migliore con cui ho potuto ottenere è un ibrido. Nel caso in cui la mia soluzione sia in qualche modo più utile nel tuo viaggio, la sto includendo qui. In bocca al lupo!

import UIKit 
import QuartzCore 

class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // the target label to apply the effect to 
     let label = UILabel(frame: view.frame) 
     // create label text with empji 
     label.text = " HELLO" 
     label.textAlignment = .center 
     // set to red to further show the greyscale change 
     label.textColor = .red 
     // calls our extension to get an image of the label 
     let image = UIImage.imageWithLabel(label: label) 
     // create a tonal filter 
     let tonalFilter = CIFilter(name: "CIPhotoEffectTonal") 
     // get a CIImage for the filter from the label image 
     let imageToBlur = CIImage(cgImage: image.cgImage!) 
     // set that image as the input for the filter 
     tonalFilter?.setValue(imageToBlur, forKey: kCIInputImageKey) 
     // get the resultant image from the filter 
     let outputImage: CIImage? = tonalFilter?.outputImage 
     // create an image view to show the result 
     let tonalImageView = UIImageView(frame: view.frame) 
     // set the image from the filter into the new view 
     tonalImageView.image = UIImage(ciImage: outputImage ?? CIImage()) 
     // add the view to our hierarchy 
     view.addSubview(tonalImageView) 
    } 
} 

extension UIImage { 
    class func imageWithLabel(label: UILabel) -> UIImage { 
     UIGraphicsBeginImageContextWithOptions(label.bounds.size, false, 0.0) 
     label.layer.render(in: UIGraphicsGetCurrentContext()!) 
     let img = UIGraphicsGetImageFromCurrentImageContext() 
     UIGraphicsEndImageContext() 
     return img! 
    } 
} 
Problemi correlati