有没有人知道如何裁剪出现在 Spotlight 搜索中的图像,以便“thumbnailData”是圆形图像而不是方形图像?
这些解决方案都无法达到预期效果: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/