Implementing “See More” Functionality on iOS: A Custom Approach

Rahul verma
Simpplr Technology
2 min readSep 25, 2023

--

Introduction: In the world of mobile app development, creating a seamless user experience is paramount. One common challenge developers often face is implementing the “See More” functionality to display truncated content with an option to expand it. Surprisingly, Apple doesn’t offer a default component for this, and despite the absence of a working third-party solution, I embarked on a journey to develop a custom setup that tackles this issue head-on. In this article, I’ll walk you through the process of implementing the “See More” functionality in iOS using my custom solution.

The Problem: Apple’s UIKit framework doesn’t come with a built-in component for handling “See More” functionality. This poses a dilemma for developers aiming to truncate lengthy content while still providing users the ability to expand it for a complete view. While some third-party libraries have attempted to address this, they often fall short or lack proper documentation.

The Custom Solution: In the absence of an out-of-the-box solution, I delved into creating a custom setup that tackles the “See More” functionality effectively. Here’s a step-by-step guide to implementing this solution in your iOS app:

Step 1: Design Your Interface
Begin by designing the interface where you’ll display the truncated content. Use a UIView component and update its class to 'SeeMoreView'.

Step 2: SeeMoreView Class
The ‘SeeMoreView’ class handles text height calculation and the show/hide more button logic. Download this file from this link.

Step 3: Configuring SeeMoreView
After adding the view to your controller, call the ‘setText’ function:

seeMoreView.setText(text: data,
isExpanded: isExpanded,
index: index,
minimumLines:3)
  • ‘text’: The complete string with “See More” capabilities.
  • ‘isExpanded’: To keep track of expanded views (useful for table/collection views).
  • ‘index’: Index of the item (useful for table/collection views).
  • ‘minimumLines’: Number of lines before showing the “More” button.

Step 4: Updating the Model
Subscribe to the seeMore view’s callback:

seeMoreView.updateSelection = { [weak self] onIndex in
let index = IndexPath(row: onIndex, section: 0)
self?.expansionStatusArr[index.row] = true
self?.tableView.reloadRows(at: [index], with: .automatic)
}

This step is only required for table/collection views with cell reuse.

Conclusion:

Despite the absence of native or third-party solutions, you now have a custom approach to seamlessly integrate the “See More” functionality into your iOS app. By following the steps outlined in this article and using the provided code snippets, you can provide users with a delightful experience when engaging with lengthy content. Elevate your app’s UX by implementing the “See More” feature and distinguish your app within the iOS ecosystem.

Feel free to explore the GitHub repository for more comprehensive code examples and further insights. Happy coding, fellow iOS developers!

--

--

Rahul verma
Simpplr Technology

I'm Rahul Verma, an iOS developer with 3.5 yrs of experience. Follow me for insights on building better mobile apps and industry trends. #iOSDev #MobileApps