簡體   English   中英

Swift-在Spotlight搜索中獲取圓形圖像(即在縮略圖中)

[英]Swift - Get a Circular Image in Spotlight Search (i.e. in the thumbnail)

是否有人對如何裁剪出現在聚光燈搜索中的圖像有任何想法,以便“ thumbnailData”是圓形圖像而不是方形圖像?

這取自RayWenderlich.com

這些解決方案均無法達到預期效果: 將UIImage切成圓圈Swift(iOS)

我可以成功裁剪圖像,但是聚光燈功能會在裁剪/遮罩的邊框周圍放置白色背景。 聚光燈聯系人(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)  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM