Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple lines title text #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 45 additions & 29 deletions Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions Example/PopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ class PopupViewController: UIViewController {
}
}
}

var titleLinesCount: Int = 1 {
didSet {
if titleLinesCountLabel != nil {
titleLinesCountLabel.text = "Number Of Lines: \(titleLinesCount)"
}

if titleLinesCountStepper != nil {
titleLinesCountStepper.value = Double(titleLinesCount)
}
}
}


var reloadClosure: (() -> Swift.Void)!

Expand All @@ -39,24 +52,32 @@ class PopupViewController: UIViewController {
@IBOutlet weak var tabItemViewWidthSlider: UISlider!
@IBOutlet weak var tabAdditionSegmentedControl: UISegmentedControl!
@IBOutlet weak var contentScrolEnabledSegmentedControl: UISegmentedControl!
@IBOutlet weak var titleLinesCountLabel: UILabel!
@IBOutlet weak var titleLinesCountStepper: UIStepper!


override func viewDidLoad() {
super.viewDidLoad()

dataCountLabel.text = "Page Number: \(dataCount)"
titleLinesCountLabel.text = "Number Of Lines: \(titleLinesCount)"

tabMarginLabel.text = "Tab Margin: \(String(format: "%.0f", Float(options.tabView.margin)))"
tabMarginSlider.setValue(Float(options.tabView.margin), animated: false)

dataCountStepper.value = Double(dataCount)
titleLinesCountStepper.value = Double(titleLinesCount)

switch options.tabView.style {
case .flexible:
styleSegmentedControl.selectedSegmentIndex = 0
dataCountStepper.maximumValue = 8
titleLinesCountStepper.maximumValue = 1
case .segmented:
styleSegmentedControl.selectedSegmentIndex = 1
dataCountStepper.maximumValue = 4
titleLinesCountStepper.maximumValue = 4
titleLinesCountStepper.minimumValue = 1
}

if options.tabView.needsAdjustItemViewWidth {
Expand Down Expand Up @@ -88,6 +109,10 @@ class PopupViewController: UIViewController {
} else {
contentScrolEnabledSegmentedControl.selectedSegmentIndex = 1
}

titleLinesCountLabel.isHidden = options.tabView.style == .flexible
titleLinesCountStepper.isHidden = options.tabView.style == .flexible
titleLinesCount = options.tabView.itemView.numberOfLines
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
Expand All @@ -102,6 +127,8 @@ class PopupViewController: UIViewController {

@IBAction func changeOptions(_ sender: UIButton) {
if let vc = self.presentingViewController as? ViewController {
options.tabView.itemView.numberOfLines = titleLinesCount
options.tabView.height = CGFloat(20 * titleLinesCount)
vc.options = options
vc.dataCount = dataCount
}
Expand All @@ -121,6 +148,10 @@ class PopupViewController: UIViewController {
@IBAction func changeDataCount(_ sender: UIStepper) {
dataCount = Int(sender.value)
}

@IBAction func changeTitleLinesCount(_ sender: UIStepper) {
titleLinesCount = Int(sender.value)
}

@IBAction func changeTabMargin(_ sender: UISlider) {
options.tabView.margin = CGFloat(sender.value)
Expand All @@ -132,9 +163,15 @@ class PopupViewController: UIViewController {
case 0:
options.tabView.style = .flexible
dataCountStepper.maximumValue = 8
titleLinesCountStepper.maximumValue = 1
if titleLinesCount > 1 || titleLinesCount == 0 {
titleLinesCount = 1
}
case 1:
options.tabView.style = .segmented
dataCountStepper.maximumValue = 4
titleLinesCountStepper.maximumValue = 4
titleLinesCountStepper.minimumValue = 1
if dataCount > 4 {
dataCount = 4
}
Expand All @@ -147,6 +184,9 @@ class PopupViewController: UIViewController {

tabItemViewWidthLabel.isHidden = options.tabView.needsAdjustItemViewWidth || options.tabView.style == .segmented
tabItemViewWidthSlider.isHidden = options.tabView.needsAdjustItemViewWidth || options.tabView.style == .segmented

titleLinesCountLabel.isHidden = options.tabView.style == .flexible
titleLinesCountStepper.isHidden = options.tabView.style == .flexible
}

@IBAction func changeAdjustTabItemWidthEnabled(_ sender: UISegmentedControl) {
Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwipeMenuViewController

final class ViewController: SwipeMenuViewController {

private var datas: [String] = ["Bulbasaur","Caterpie", "Golem", "Jynx", "Marshtomp", "Salamence", "Riolu", "Araquanid"]
private var datas: [String] = ["This is my first tab with three lines","My second tab 2 lines", "Third tab", "Jynx", "Marshtomp", "Salamence", "Riolu", "Araquanid"]

var options = SwipeMenuViewOptions()
var dataCount: Int = 5
Expand Down
4 changes: 4 additions & 0 deletions Sources/Classes/SwipeMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public struct SwipeMenuViewOptions {

/// ItemView selected textColor. Defaults to `.black`.
public var selectedTextColor: UIColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)

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

}

public struct AdditionView {
Expand Down
9 changes: 6 additions & 3 deletions Sources/Classes/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ open class TabView: UIScrollView {
tabItemView.translatesAutoresizingMaskIntoConstraints = false
tabItemView.clipsToBounds = options.clipsToBounds
if let title = dataSource.tabView(self, titleForItemAt: index) {
let itemView = options.itemView

tabItemView.titleLabel.text = title
tabItemView.titleLabel.font = options.itemView.font
tabItemView.textColor = options.itemView.textColor
tabItemView.selectedTextColor = options.itemView.selectedTextColor
tabItemView.titleLabel.numberOfLines = itemView.numberOfLines
tabItemView.titleLabel.font = itemView.font
tabItemView.textColor = itemView.textColor
tabItemView.selectedTextColor = itemView.selectedTextColor
}

tabItemView.isSelected = index == currentIndex
Expand Down