0

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?

This is taken from RayWenderlich.com

None of these solutions work to the desired effect: Cut a UIImage into a circle 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).

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
}
Community
  • 1
  • 1
David West
  • 1,550
  • 1
  • 18
  • 31

1 Answers1

4

I came across the same issue as well.

Assuming your image has a transparent background, what worked for me was

 attributeSet.thumbnailData = UIImagePNGRepresentation(profileImage)