ios - Swift - 在 Spotlight 搜索中获取圆形图像(即在缩略图中)

标签 ios uiimage corespotlight uiimagejpegrepresentation

有没有人知道如何裁剪出现在 Spotlight 搜索中的图像,以便“thumbnailData”是圆形图像而不是方形图像?

This is taken from RayWenderlich.com

这些解决方案都无法达到预期效果:Cut a UIImage into a circle Swift(iOS)

我可以成功裁剪图像,但聚光灯功能会在裁剪/遮盖的边框周围放置一个白色背景。 Spotlight 联系人 (kUTTypeContact) 是可能的,只是不是我所看到的内容 (kUTTypeContent)。

这是我的代码,供所有研究人员查看:

    // For storing attributes into Searchable Dictionary
    internal var attributeSet: CSSearchableItemAttributeSet {
    let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeContent as String)
    attributeSet.title = "\(firstName) \(surname)"
    attributeSet.contentDescription = location
    attributeSet.keywords = ["tennis", "scorelord", firstName, surname, handed, location, "\(itnLevel)"]
    attributeSet.thumbnailData = UIImageJPEGRepresentation(profileImage, 0.8)
    attributeSet.thumbnailData?.displayLayer(<#T##layer: CALayer##CALayer#>)
    return attributeSet
}

最佳答案

我也遇到了同样的问题。

假设您的图像具有透明背景,对我有用的是

 attributeSet.thumbnailData = UIImagePNGRepresentation(profileImage)  

关于ios - Swift - 在 Spotlight 搜索中获取圆形图像(即在缩略图中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36465707/

相关文章:

swift - 当我打开 Skype、FB、Twitter,但我们的应用程序正在使用 swift 后台运行时,如何截取屏幕截图

ios - 将 UIImage 的 "Tick Marks"添加到 UISlider

ios - CoreSpotlight 索引不起作用

ios - Jenkins + iOS + TestFlight API

iphone - UILocalNotification如何实现 "Alarm"?

objective-c - 清除UIImage使用的内存— UIImageView.image = nil不这样做

ios - 如何让 CoreSpotlight 预测谁来电

来自 URL 的 iOS CoreSpotlight 缩略图

ios - 如何为完整的应用程序实现 uisearchcontroller

ios - 如何弹出到另一个堆栈上存在的 View Controller ?