Customize the Search Result Cell in Swift for iOS

Use a custom text colors in the table view cell for PSPDFSearchViewController. Get additional resources by visiting PDF search library for iOS.


//
// Copyright © 2019-2025 PSPDFKit GmbH. All rights reserved.
//
// The Nutrient sample applications are licensed with a modified BSD license.
// Please see License for details. This notice may not be removed from this file.
//
import PSPDFKit
import PSPDFKitUI
class CustomSearchResultCellExample: Example {
override init() {
super.init()
title = "Custom Search Result Cell"
contentDescription = "Shows how to customize the table view cell for PSPDFSearchViewController."
category = .viewCustomization
priority = 60
}
override func invoke(with delegate: ExampleRunnerDelegate) -> UIViewController {
let document = AssetLoader.writableDocument(for: .welcome, overrideIfExists: false)
let controller = PDFViewController(document: document) {
$0.overrideClass(SearchViewController.self, with: CustomSearchViewController.self)
}
return controller
}
}
private class CustomSearchResultTableViewCell: UITableViewCell, SearchResultViewable {
func configure(with searchResult: SearchResult) {
// Custiomize the cell.
textLabel?.text = searchResult.previewText
textLabel?.textColor = UIColor.systemGreen
textLabel?.numberOfLines = 0
textLabel?.adjustsFontForContentSizeCategory = true
let document = searchResult.document
let pageIndex = searchResult.pageIndex
let size = CGSize(width: 32, height: 32)
imageView?.contentMode = UIView.ContentMode.scaleAspectFit
imageView?.image = try! document?.imageForPage(at: pageIndex, size: size, clippedTo: CGRect.zero, annotations: nil, options: nil)
}
}
private class CustomSearchViewController: SearchViewController {
override class func resultCellClass() -> (SearchResultViewable.Type) {
return CustomSearchResultTableViewCell.self
}
}

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.