|
|
1 vuosi sitten | |
|---|---|---|
| .. | ||
| Sources | 1 vuosi sitten | |
| LICENSE | 1 vuosi sitten | |
| README-English.md | 1 vuosi sitten | |

A powerful and easy to use segmented view (segmentedcontrol, pagingview, pagerview, pagecontrol, categoryview)
Advantages compared to other similar tripartite libraries:
If you are looking for the Objective-C version, please click to view JXCategoryView
The following indicators support up and down position switching:
JXSegmentedIndicatorLineView、JXSegmentedIndicatorRainbowLineView、JXSegmentedIndicatorDotLineView、JXSegmentedIndicatorDoubleLineView、JXSegmentedIndicatorTriangleView、JXSegmentedIndicatorImageView
| Description | Gif |
|---|---|
| less data isItemSpacingAverageEnabled is true |
![]() |
| less data isItemSpacingAverageEnabled is false |
![]() |
| SegmentedControl reference SegmentedControlViewController |
![]() |
| SegmentedControl reference SegmentedControlViewController |
![]() |
| use in navigation bar reference NaviSegmentedControlViewController |
![]() |
| nestable reference NestViewController |
![]() |
| user profile page reference PagingViewControllermore styles just clickJXPagingView |
![]() |
| data load & refresh reference LoadDataViewController |
![]() |
Clone the code and drag the Sources folder into the project to use it.
target '<Your Target Name>' do
pod 'JXSegmentedView'
end
Execute pod repo update first, then execute pod install
JXSegmentedView example1.JXSegmentedView initialize
self.segmentedView = JXSegmentedView()
self.segmentedView.delegate = self
self.view.addSubview(self.segmentedView)
2.dataSource initialize
The dataSouce type is the JXSegmentedViewDataSource protocol. Use a separate class to implement the JXSegmentedViewDataSource protocol for code isolation. By selecting different class assignments to dataSource, you can control the JXSegmentedView display effect and implement plugin. For example, selecting the JXSegmentedTitleImageDataSource class as the dataSource selects the display effect of the text image; selecting the JXSegmentedNumberDataSource class as the dataSource selects the display effect of the text & number;
//segmentedDataSource must be strongly held by the property, or it will be released
self.segmentedDataSource = JXSegmentedTitleDataSource()
//Configuring data source related properties
self.segmentedDataSource.titles = ["猴哥", "青蛙王子", "旺财"]
self.segmentedDataSource.isTitleColorGradientEnabled = true
//The reloadData(selectedIndex:) method must be called, and the method will internally refresh the data source array.
self.segmentedDataSource.reloadData(selectedIndex: 0)
//Associated dataSource
self.segmentedView.dataSource = self.segmentedDataSource
3.Indicator initialize
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 20
self.segmentedView.indicators = [indicator]
4.Implement JXSegmentedViewDelegate
//This method is called when you click to select or scroll to select. Applicable to only care about selected events, regardless of whether it is click or scroll.
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {}
// This method will be called when the selected condition is clicked.
func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {}
// This method is called when the scroll is selected.
func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {}
// Then callback when scrolling
func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {}
contentScrollView list container usage exampleUIScrollView custom usage example directlyBecause the code is scattered and the amount of code is large, it is not recommended. There are many places to pay attention to when using it properly, especially for students who are new to iOS.
Do not directly paste the code, click LoadDataCustomViewController to view the source code.
As an alternative, the official use & is highly recommended to use the following in this way 👇👇👇.
JXSegmentedListContainerView wrapper classJXSegmentedListContainerView is a highly encapsulated class for list views with the following advantages:
UIScrollView customization, the package is high, the code is centralized, and the use is simple;1.JXSegmentedListContainerView initialize
self.listContainerView = JXSegmentedListContainerView(dataSource: self)
self.view.addSubview(self.listContainerView)
//Associate the cotentScrollView
self.segmentedView.contentScrollView = self.listContainerView.scrollView
2.Implement JXSegmentedListContainerViewDataSource
//return numbers of lists
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return self.segmentedDataSource.titles.count
}
//return the instance which comform `JXSegmentedListContainerViewListDelegate`
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
return ListBaseViewController()
}
3.Implement JXSegmentedListContainerViewListDelegate for list
Regardless of whether the type of the list is UIView or UIViewController
/// If the list is VC, return VC.view
/// If the list is View, return to View itself
/// - Returns: list
func listView() -> UIView {
return view
}
//Optional use, when the list is displayed
func listDidAppear() {}
//Optional use, called when the list disappears
func listDidDisappear() {}
4.Tell the key event JXSegmentedListContainerView
In the following two JXSegmentedViewDelegate proxy methods, call the corresponding code, don't forget this one❗️❗️❗️
func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
//Pass the didClickSelectedItemAt event to the listContainerView, which must be called! ! !
listContainerView.didClickSelectedItem(at: index)
}
func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
//Pass the scrolling event to the listContainerView, which must be called! ! !
listContainerView.segmentedViewScrolling(from: leftIndex, to: rightIndex, percent: percent, selectedIndex: segmentedView.selectedIndex)
}
Click LoadDataViewController to see the source code.
Because JXSegmentedView supports many features: indicators, cell styles, list containers, etc. How to manage the code orderly becomes a problem. The use of protocols, inheritance, and encapsulation classes greatly simplifies the use, and increases flexibility, making extensions quite easy.
JXSegmentedViewJXSegmentedViewDataSource protocolUIView class that complies with the JXSegmentedIndicatorProtocol protocolJXSegmentedListContainerView class, special case can be customized using UIScrollViewJXSegmentedIndicatorProtocol protocol, click on JXSegmentedIndicatorProtocolJXSegmentedIndicatorBaseView inheriting the JXSegmentedIndicatorProtocol protocol is provided, which provides many basic properties. Click to see JXSegmentedIndicatorBaseViewJXSegmentedViewDataSource protocol, click on JXSegmentedViewDataSourceJXSegmentedBaseDataSource that inherits the JXSegmentedViewDataSource protocol, which provides many basic properties. Click to see JXSegmentedBaseDataSourceCommon attribute description document address
Other usage tips document address
If you are just starting to use JXSegmentedView, be sure to search for the documentation or source code when you need to support certain features during development. Confirm that you have implemented the features you want to support. Please don't ask the documentation and source code to see it, just ask questions directly. This is a waste of time for everyone. If you don't support the features you want, feel free to ask for an discussion, or implement a PullRequest yourself.
If you have any suggestions or questions, you can contact me by:
E-mail:317437084@qq.com QQ Group: 112440276If you like, just star❤️ it.
JXSegmentedView is released under the MIT license.