2013-04-01 24 views
9

Tôi muốn sử dụng của Apple được xây dựng-in ký tự emoji (đặc biệt là một số trong những biểu tượng mặt cười, ví dụ như \ue415) trong một UILabel nhưng tôi muốn các biểu tượng cảm xúc để được trả lại trong màu xám.Make ký tự emoji màu xám trong UILabel

tôi muốn họ giữ nguyên các ký tự trong số UILabel (hoặc văn bản thuần túy hoặc được gán là tốt) .Tôi không tìm kiếm giải pháp chuỗi hình ảnh/chuỗi lai (mà tôi đã có)

Có ai biết cách thực hiện điều này không?

+0

Bạn đã bao giờ tìm được giải pháp cho điều này chưa? –

+0

@AlexBeals tiếc là không. – DrewInTheMountains

Trả lời

0

Tôi biết bạn đã nói rằng bạn không tìm kiếm một "lai im giải pháp tuổi tác ", nhưng tôi đã theo đuổi con rồng này trong một thời gian và kết quả tốt nhất tôi có thể đến với IS lai. Chỉ trong trường hợp giải pháp của tôi bằng cách nào đó hữu ích hơn trong hành trình của bạn, tôi sẽ đưa nó vào đây. Chúc may mắn!

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! 
    } 
} 
Các vấn đề liên quan