简体   繁体   English

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

[英]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”是圆形图像而不是方形图像?

这取自RayWenderlich.com

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.

相关问题 CoreSpotlight缩略图图像未显示在Spotlight搜索上 - CoreSpotlight Thumbnail Image not showing up on Spotlight search 使用CoreSpotlight的iOS 9 Spotlight搜索:无法替换缩略图 - iOS 9 Spotlight Search with CoreSpotlight: cannot replace thumbnail 从UITabBarController(Swift)打开(即转到)特定的序列 - Open (i.e. go to) specific segue from UITabBarController (Swift) iOS10 Swift 3 Core Spotlight Search无法获得nsuseractivity的标题 - Ios10 swift 3 core spotlight search cant get title of nsuseractivity 获取对本地符号的引用(即使其成为外部符号) - Get a reference to local symbol (i.e. make it external) 如何从Spotlight搜索中启动该应用程序? - How to get that application launch from spotlight search? 如何从Swift中的UIPickerViewController中获取视频的缩略图? - How to get thumbnail image of video picked from UIPickerViewController in Swift? 如何从Swift中的ALAssetRepresentation获取低分辨率图像或缩略图 - How to get a low res image, or Thumbnail from the ALAssetRepresentation in Swift Dropbox-iOS- Swift 3:无法获取缩略图 - Dropbox - IOS- Swift 3 : Cannot get the thumbnail image iOS Swift - 如何匹配“像”另一个字符串的字符串? 即“http”就像“http://” - iOS Swift - How to match a string that is “like” another string? i.e. “http” is like “http://”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM