It's been a long time since I brought you some useful information about iOS development. Today, I'd like to share with you an example of switching between categories in a headline news client. In the demo, the required components are simply encapsulated, and the encapsulated components are in the form of pure code. If you want to use them in your project, you can just make some minor modifications. Without further ado, let me introduce the functions first. The figure below shows the functions of the entire Demo. The TabBarButtonItem on the top left is used to reduce items. For example, there are three buttons in the figure below. Clicking the minus sign will reduce an item. The one on the right is to add an item. Clicking the corresponding button will switch to the corresponding table view. The red one below is the sliding indicator, which also supports gesture sliding. The specific effect of running is shown in the figure below. 1. Implementation plan At the top is a View with some buttons instantiated on it, dividing the width of the screen equally. Below is a ScrollView with some table views placed on it. Click different buttons to slide to the corresponding representation. In addition to clicking buttons, you can also slide to switch. When switching, the red indicator will also slide. The main technical point is to change the value of ScrollView's ContentOffset through the callback of ScrollView and the response of the event. In the callback, the offset of the red indicator is calculated according to the value of ContentOffset. 2. Core code 1. Main properties in the component Encapsulate the entire view above and name it SlideTabBarView. The following code is the main properties:
2. The initialization method is as follows. When calling the initialization method, you need to pass in the frame of SlideTabBarView and the number of tabs. The initialization function will call a series of initialization methods to initialize the components. The code is as follows:
3. The initDataSource method is mainly responsible for simulating the generation of data to be displayed in the TableView below. The code is as follows:
4. The initialization code of the red sliding indicator is as follows:
5. The initialization code of ScrollView is as follows, which specifies the size, position and background color of ScrollView, enables paging and adds a proxy.
6. Add the buttons above and instantiate multiple buttons according to the number passed in.
7. Click the button to trigger the method as follows:
8. Initialize the multiple table views below: Instantiate the table views and specify the delegate callback.
9. The callback method of ScrollView is as follows. The first proxy method below calculates the offset of the red indicator based on the offset of ScrollView. The second one is to slide to which tableView and then load the data of which TableView.
10. The proxy method of TableView is as follows. The data source is the fake data we just made. Cell is implemented by Xib. It can be used by registering it when using it.
|
<<: You should use Node.js for your side projects
>>: Tutorials can make or break a game: A brief analysis of the design of a tutorial for new players
After Tesla, one of the representatives of new ca...
Author: Zhang Haicheng, Chief Physician, Peking U...
Recently, a stacking elimination game called &quo...
Author | Derek Yang, senior R&D manager at Ct...
A huge network formed by connecting networks with...
Source code introduction: Android slides to close...
In the era of comprehensive TV intelligence, the ...
Hound was born out of the music radar application...
What is the general charge for making a mini prog...
Apple released the iPhone 6 Plus, and Honor broug...
Compared to 2015, there are not many smart hardwa...
Dasou ocpc is a double-edged sword. If used well,...
Mini programs provide convenience for publicity a...
The topic I’m going to share with you today is da...
Friends around me often ask me how to organize ac...