yysskk / SwipeMenuViewController

Swipable tab and menu View and ViewController.
MIT License
1.29k stars 131 forks source link

Added support for multiple lines title text #123

Open Satish24sp opened 1 year ago

Satish24sp commented 1 year ago

Added support for multiple lines title text with swipe menu segment style so that we can overcome the issue of text truncation.

Support has been added in the below classes:

1. SwipeMenuView.swift at L38 to L41 Added new public parameter in a function i.e. public struct ItemView {....} After:

 /// ItemView title number of lines . Defaults to `1`.
      public var numberOfLines: Int = 1

2. TabView.swift at L218 to L224. Modified the existing function i.e. fileprivate func setupTabItemViews(dataSource: TabViewDataSource) {....} Before:

if let title = dataSource.tabView(self, titleForItemAt: index) {
   tabItemView.titleLabel.text = title
   tabItemView.titleLabel.font = options.itemView.font
   tabItemView.textColor = options.itemView.textColor
   tabItemView.selectedTextColor = options.itemView.selectedTextColor
}

After:


if let title = dataSource.tabView(self, titleForItemAt: index) {
   let itemView = options.itemView

   tabItemView.titleLabel.text = title
   tabItemView.titleLabel.numberOfLines = itemView.numberOfLines      // Change for multiple lines
   tabItemView.titleLabel.font = itemView.font
   tabItemView.textColor = itemView.textColor
   tabItemView.selectedTextColor = itemView.selectedTextColor
}

Final Result:

Before Changes: Simulator Screenshot - iPhone 14 Pro - 2023-09-13 at 20 52 11

After Changes: Simulator Screenshot - iPhone 14 Pro - 2023-09-13 at 20 52 21

Regards.