[英]Swift - Get a Circular Image in Spotlight Search (i.e. in the thumbnail)
Does anyone have any ideas as to how to go about cropping the image that appears in the spotlight search, so that 'thumbnailData' is a circular image not a square one? 是否有人对如何裁剪出现在聚光灯搜索中的图像有任何想法,以便“ thumbnailData”是圆形图像而不是方形图像?
None of these solutions work to the desired effect: Cut a UIImage into a circle Swift(iOS) 这些解决方案均无法达到预期效果: 将UIImage切成圆圈Swift(iOS)
I can successfully crop the image but then spotlight feature puts a white background around the cropped/masked border. 我可以成功裁剪图像,但是聚光灯功能会在裁剪/遮罩的边框周围放置白色背景。 It's possible with spotlight contacts (kUTTypeContact), just not content from what I can see (kUTTypeContent).
聚光灯联系人(kUTTypeContact)可能存在,但我所看到的内容(kUTTypeContent)却没有。
Here is my code for any boffins out there to take a peek: 这是我的代码,供您偷看其他棺材:
// 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
}
I came across the same issue as well. 我也遇到了同样的问题。
Assuming your image has a transparent background, what worked for me was 假设您的图片具有透明背景,对我有用的是
attributeSet.thumbnailData = UIImagePNGRepresentation(profileImage)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.